mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
Fix spacebar bug in Firefox
This commit is contained in:
parent
781b7c20fe
commit
9d15010f4a
@ -5,7 +5,7 @@ import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange';
|
||||
import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition';
|
||||
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
|
||||
|
||||
import { defaultConfig, extractDelimiters, hasDelimiters, delimitersCounts } from './utils';
|
||||
import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils';
|
||||
|
||||
export default class AutoMath extends Plugin {
|
||||
static get requires() {
|
||||
@ -59,7 +59,7 @@ export default class AutoMath extends Plugin {
|
||||
_mathBetweenPositions( leftPosition, rightPosition ) {
|
||||
const editor = this.editor;
|
||||
|
||||
const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) );
|
||||
const mathConfig = this.editor.config.get( 'math' );
|
||||
|
||||
const equationRange = new LiveRange( leftPosition, rightPosition );
|
||||
const walker = equationRange.getWalker( { ignoreElementEnd: true } );
|
||||
|
@ -1,10 +1,10 @@
|
||||
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
||||
import { toWidget } from '@ckeditor/ckeditor5-widget/src/utils';
|
||||
import { toWidget, viewToModelPositionOutsideModelElement } from '@ckeditor/ckeditor5-widget/src/utils';
|
||||
import Widget from '@ckeditor/ckeditor5-widget/src/widget';
|
||||
|
||||
import MathCommand from './mathcommand';
|
||||
|
||||
import { defaultConfig, renderEquation, extractDelimiters } from './utils';
|
||||
import { renderEquation, extractDelimiters } from './utils';
|
||||
|
||||
export default class MathEditing extends Plugin {
|
||||
static get requires() {
|
||||
@ -21,6 +21,17 @@ export default class MathEditing extends Plugin {
|
||||
|
||||
this._defineSchema();
|
||||
this._defineConverters();
|
||||
|
||||
editor.editing.mapper.on(
|
||||
'viewToModelPosition',
|
||||
viewToModelPositionOutsideModelElement( editor.model, viewElement => viewElement.hasClass( 'math' ) )
|
||||
);
|
||||
editor.config.define( 'math', {
|
||||
engine: 'mathjax',
|
||||
outputType: 'script',
|
||||
forceOutputType: false,
|
||||
enablePreview: true
|
||||
} );
|
||||
}
|
||||
|
||||
_defineSchema() {
|
||||
@ -36,7 +47,7 @@ export default class MathEditing extends Plugin {
|
||||
|
||||
_defineConverters() {
|
||||
const conversion = this.editor.conversion;
|
||||
const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) );
|
||||
const mathConfig = this.editor.config.get( 'math' );
|
||||
|
||||
// View -> Model
|
||||
conversion.for( 'upcast' )
|
||||
@ -114,13 +125,11 @@ export default class MathEditing extends Plugin {
|
||||
const styles = 'user-select: none; ' + ( display ? '' : 'display: inline-block;' );
|
||||
const classes = 'ck-math-tex ' + ( display ? 'ck-math-tex-display' : 'ck-math-tex-inline' );
|
||||
|
||||
// CKEngine render multiple times if using span instead of div
|
||||
const mathtexView = viewWriter.createContainerElement( 'div', {
|
||||
const mathtexView = viewWriter.createContainerElement( 'span', {
|
||||
style: styles,
|
||||
class: classes
|
||||
} );
|
||||
|
||||
// Div is formatted as parent container
|
||||
const uiElement = viewWriter.createUIElement( 'div', null, function( domDocument ) {
|
||||
const domElement = this.toDomElement( domDocument );
|
||||
|
||||
|
@ -10,7 +10,6 @@ import MainFormView from './ui/mainformview';
|
||||
|
||||
// Need math commands from there
|
||||
import MathEditing from './mathediting';
|
||||
import { defaultConfig } from './utils';
|
||||
|
||||
import mathIcon from '../theme/icons/math.svg';
|
||||
|
||||
@ -69,7 +68,7 @@ export default class MathUI extends Plugin {
|
||||
const editor = this.editor;
|
||||
const mathCommand = editor.commands.get( 'math' );
|
||||
|
||||
const mathConfig = Object.assign( defaultConfig, this.editor.config.get( 'math' ) );
|
||||
const mathConfig = this.editor.config.get( 'math' );
|
||||
|
||||
const formView = new MainFormView( editor.locale, mathConfig.engine, mathConfig.enablePreview, this._previewUid );
|
||||
|
||||
@ -111,7 +110,7 @@ export default class MathUI extends Plugin {
|
||||
|
||||
this._balloon.add( {
|
||||
view: this.formView,
|
||||
position: this._getBalloonPositionData(),
|
||||
position: this._getBalloonPositionData()
|
||||
} );
|
||||
|
||||
if ( this._balloon.visibleView === this.formView ) {
|
||||
|
13
src/utils.js
13
src/utils.js
@ -2,13 +2,6 @@
|
||||
|
||||
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
|
||||
|
||||
export const defaultConfig = {
|
||||
engine: 'mathjax',
|
||||
outputType: 'script',
|
||||
forceOutputType: false,
|
||||
enablePreview: true
|
||||
};
|
||||
|
||||
export function getSelectedMathModelWidget( selection ) {
|
||||
const selectedElement = selection.getSelectedElement();
|
||||
|
||||
@ -24,7 +17,7 @@ export function isMathJaxVersion3( version ) {
|
||||
return version && typeof version === 'string' && version.split( '.' ).length === 3 && version.split( '.' )[ 0 ] === '3';
|
||||
}
|
||||
|
||||
// Check if equation has delimiters
|
||||
// Check if equation has delimiters.
|
||||
export function hasDelimiters( text ) {
|
||||
return text.match( /^(\\\[.*?\\\]|\\\(.*?\\\))$/ );
|
||||
}
|
||||
@ -108,7 +101,7 @@ function selectRenderMode( element, preview, previewUid, cb ) {
|
||||
}
|
||||
}
|
||||
|
||||
function renderMathJax3( equation, element, display, after ) {
|
||||
function renderMathJax3( equation, element, display, cb ) {
|
||||
let promiseFunction = undefined;
|
||||
if ( typeof MathJax.tex2chtmlPromise !== 'undefined' ) {
|
||||
promiseFunction = MathJax.tex2chtmlPromise;
|
||||
@ -122,7 +115,7 @@ function renderMathJax3( equation, element, display, after ) {
|
||||
element.removeChild( element.firstChild );
|
||||
}
|
||||
element.appendChild( node );
|
||||
after();
|
||||
cb();
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user