-
Notifications
You must be signed in to change notification settings - Fork 20
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
CodeMirror 6 / beta editor support #93
Conversation
alondmnt
commented
Mar 28, 2024
- Tested on desktop
- Tested on mobile
src/codeMirror6Scroller.ts
Outdated
plugin: (editorControl: any) => { | ||
if (!editorControl.cm6) { return; } | ||
|
||
// Running in CM6 | ||
editorControl.registerCommand('scrollToLine', (lineNumber: number) => { | ||
const editor: EditorView = editorControl.editor; | ||
console.log('scrollToLine', lineNumber); | ||
|
||
// Bounds checking | ||
if (lineNumber < 0) { | ||
lineNumber = 0; | ||
} | ||
if (lineNumber > editor.state.doc.lines) { | ||
lineNumber = editor.state.doc.lines; | ||
} | ||
|
||
// Scroll to line, place the line at the *top* of the editor | ||
const lineInfo = editor.state.doc.line(lineNumber); | ||
editor.dispatch(editor.state.update({ | ||
effects: EditorView.scrollIntoView(lineInfo.from, {y: 'start'}) | ||
})); | ||
}); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alondmnt This currently uses mixed tabs and space indentation.
(Thank you for working on this!)
Also note that if upgrading the plugin API proves to be too big of a change for this pull request, it should be possible to require CodeMirror 6 modules (with no types) with joplin.require
. For example,
const { EditorView } = joplin.require('@codemirror/view');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, missed those tabs (fixed).
Also accidentally installed @codemirror/view
not as a dev dependency (fixed).
As for the joplin.require trick (thanks!), I had an issue with it so left it as is for now. If you or cqroot feel that this is necessary will try to resolve it.
refactor: fix eslint error