-
Notifications
You must be signed in to change notification settings - Fork 17
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
Open
alondmnt
wants to merge
10
commits into
cqroot:main
Choose a base branch
from
alondmnt:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,186
−11,176
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e087357
update: env & api/types
alondmnt ca74eb4
new: CodeMirror6 support
alondmnt ad69afa
fix: CM5 / CM6 script loading logic
alondmnt df7fff8
chore: formatting
alondmnt 352fd40
improve: line number bounds
alondmnt 6be4b05
improve: moved @codemirror/view to devDependencies
alondmnt ee2cb23
fix: scroll 1-line shift
alondmnt 78915ca
refactor: fix eslint error
cqroot 3c2f44f
Merge pull request #1 from cqroot/alondmnt
alondmnt 41a5ce1
fix: scroll in mobile viewer
alondmnt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"extraScripts": [] | ||
"extraScripts": ["codeMirror6Scroller.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { ContentScriptContext, MarkdownEditorContentScriptModule } from 'api/types'; | ||
import { EditorView } from '@codemirror/view'; | ||
|
||
// modified from: https://github.com/personalizedrefrigerator/bug-report/tree/example/plugin-scroll-to-line | ||
export default (context: ContentScriptContext): MarkdownEditorContentScriptModule => { | ||
return { | ||
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'}) | ||
})); | ||
}); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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,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.