Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Mod-a to select all KaTeX text for math NodeView and fix selectors error #72

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/commands/collapse-math-cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ export function collapseMathCmd(
// set outer selection to be outside of the nodeview
let targetPos: number = (dir > 0) ? outerTo : outerFrom;

// must return focus to the outer view, otherwise no cursor will appear
outerView.focus();

outerView.dispatch(
outerState.tr.setSelection(
TextSelection.create(outerState.doc, targetPos)
)
);

// must return focus to the outer view, otherwise no cursor will appear
outerView.focus();
//if innerView at the end of outerView, insert new line at end of outerView
if (targetPos == outerState.doc.content.size){
outerView.dispatch(
outerState.tr.insert(targetPos, outerState.schema.nodes.paragraph.create())
)
}

}

return true;
Expand Down
17 changes: 15 additions & 2 deletions lib/math-nodeview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// prosemirror imports
import { Node as ProseNode } from "prosemirror-model";
import { EditorState, Transaction, TextSelection, PluginKey } from "prosemirror-state";
import {EditorState, Transaction, TextSelection, PluginKey, NodeSelection} from "prosemirror-state";
import { NodeView, EditorView, Decoration } from "prosemirror-view";
import { history, redo, undo } from 'prosemirror-history'
import { StepMap } from "prosemirror-transform";
import { keymap } from "prosemirror-keymap";
import { newlineInCode, chainCommands, deleteSelection } from "prosemirror-commands";
Expand Down Expand Up @@ -259,7 +260,19 @@ export class MathView implements NodeView {
"ArrowRight" : collapseMathCmd(this._outerView, +1, true),
"ArrowUp" : collapseMathCmd(this._outerView, -1, true),
"ArrowDown" : collapseMathCmd(this._outerView, +1, true),
})]
"Mod-a" : ()=>{
this._innerView?.dispatch(this._innerView?.state.tr.setSelection(NodeSelection.create(this._innerView?.state.doc,0)))
return true
},
"Mod-z" : ()=>{
undo(this._innerView?.state!, this._innerView?.dispatch)
return true
},
"Mod-y" : ()=>{
redo(this._innerView?.state!, this._innerView?.dispatch)
return true
},
}),history()]
}),
dispatchTransaction: this.dispatchInner.bind(this)
})
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/math-paste-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function texFromMathML_01(root: Element): false|string {
* <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">
*/
function texFromMathML_02(root: Element): false|string {
let match = root.querySelector("math annotation[encoding='application/x-tex'");
let match = root.querySelector("math annotation[encoding='application/x-tex']");
return (match?.textContent ?? false);
}

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
"prosemirror-model": "^1.20.0",
"prosemirror-state": "^1.4.3",
"prosemirror-transform": "^1.8.0",
"prosemirror-view": "^1.33.4"
"prosemirror-view": "^1.33.7"
}
}
2 changes: 2 additions & 0 deletions public/prosemirror-math.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ math-inline .math-render {
cursor:pointer;
}

math-inline.ProseMirror-selectednode { background-color: #eee; }

math-inline .math-src .ProseMirror {
display: inline;
/* Necessary to fix FireFox bug with contenteditable, https://bugzilla.mozilla.org/show_bug.cgi?id=1252108 */
Expand Down