mirror of
https://github.com/fjdu/obsidian-latex-unicode.git
synced 2026-07-22 07:30:30 +00:00
refactor: added KeyboardEvent type, fixed comments
This commit is contained in:
parent
2aa4b331ae
commit
82b8b5ab8a
1 changed files with 5 additions and 6 deletions
11
main.ts
11
main.ts
|
|
@ -7,7 +7,6 @@ export default class LaTeXtoUnicode extends Plugin {
|
|||
id: "latex-to-unicode",
|
||||
name: "LaTeX to Unicode",
|
||||
editorCallback: (editor: Editor) => {
|
||||
|
||||
const onSubmit = (res: string) => {
|
||||
insertRange(editor,res)
|
||||
};
|
||||
|
|
@ -23,13 +22,13 @@ function insertRange(editor : Editor, text : string)
|
|||
var pos = editor.getCursor()
|
||||
var offset = editor.posToOffset(pos);
|
||||
|
||||
editor.replaceRange(text, pos); // Replace (cursor will be pushed by the length of the text)
|
||||
editor.replaceRange(text, pos); // Replace (cursor will NOT be pushed by the length of the text)
|
||||
|
||||
editor.setCursor(editor.offsetToPos(offset+text.length)) // Go back by one, resulting in the position after the replace
|
||||
editor.setCursor(editor.offsetToPos(offset+text.length)) // Go forward to the end of the replace, for the "insert" effect
|
||||
}
|
||||
|
||||
export class LaTeXToUnicodeModal extends Modal {
|
||||
res: string;
|
||||
res: string = "";
|
||||
|
||||
onSubmit: (res: string) => void;
|
||||
|
||||
|
|
@ -56,8 +55,8 @@ export class LaTeXToUnicodeModal extends Modal {
|
|||
valueChanged?.()
|
||||
})
|
||||
.inputEl
|
||||
.addEventListener('keypress',
|
||||
(e) => {
|
||||
.addEventListener('keyup',
|
||||
(e : KeyboardEvent) => {
|
||||
if(e.key == "Enter")
|
||||
{
|
||||
this.onSubmit(this.res)
|
||||
|
|
|
|||
Loading…
Reference in a new issue