-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Desktop: Improve beta editor support for the Rich Markdown plugin #9935
Merged
laurent22
merged 13 commits into
laurent22:dev
from
personalizedrefrigerator:pr/changes-to-support-richmarkdown
Mar 9, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
509da44
Desktop: Beta editor: Fix search results not highlighted
personalizedrefrigerator b36ff9e
Add test
personalizedrefrigerator e162f03
Revert unnecessary change
personalizedrefrigerator af9ebbc
Desktop: Support rich markdown plugin in the beta editor with minimal…
personalizedrefrigerator 7a70dcf
Line widget fixes
personalizedrefrigerator 19ade0b
Fix table monospacing
personalizedrefrigerator 5ff7fff
Fix PluginLoader tests
personalizedrefrigerator 6ebe9d8
Merge remote-tracking branch 'upstream/dev' into pr/changes-to-suppor…
personalizedrefrigerator 262953a
Remove additional each-line class
personalizedrefrigerator d920456
Merge remote-tracking branch 'upstream/dev' into pr/changes-to-suppor…
personalizedrefrigerator cac9983
Spelling fixes
personalizedrefrigerator 0bd691b
Merge remote-tracking branch 'upstream/dev' into pr/changes-to-suppor…
personalizedrefrigerator 8bd1bf9
Fix function duplicated by merge
personalizedrefrigerator 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
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
83 changes: 83 additions & 0 deletions
83
packages/editor/CodeMirror/CodeMirror5Emulation/CodeMirror5BuiltInOptions.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Compartment, Extension, RangeSetBuilder, StateEffect } from '@codemirror/state'; | ||
import { Decoration, DecorationSet, EditorView, ViewPlugin, ViewUpdate } from '@codemirror/view'; | ||
|
||
const activeLineDecoration = Decoration.line({ class: 'CodeMirror-activeline CodeMirror-activeline-background' }); | ||
|
||
const optionToExtension: Record<string, Extension> = { | ||
'styleActiveLine': [ | ||
ViewPlugin.fromClass(class { | ||
public decorations: DecorationSet; | ||
|
||
public constructor(view: EditorView) { | ||
this.updateDecorations(view); | ||
} | ||
|
||
public update(update: ViewUpdate) { | ||
this.updateDecorations(update.view); | ||
} | ||
|
||
private updateDecorations(view: EditorView) { | ||
const builder = new RangeSetBuilder<Decoration>(); | ||
let lastLine = -1; | ||
|
||
for (const selection of view.state.selection.ranges) { | ||
const startLine = selection.from; | ||
const line = view.state.doc.lineAt(startLine); | ||
|
||
if (line.number !== lastLine) { | ||
builder.add(line.from, line.from, activeLineDecoration); | ||
} | ||
|
||
lastLine = line.number; | ||
} | ||
|
||
this.decorations = builder.finish(); | ||
} | ||
}, { | ||
decorations: plugin => plugin.decorations, | ||
}), | ||
EditorView.baseTheme({ | ||
'&dark .CodeMirror-activeline-background': { | ||
background: '#3304', | ||
color: 'white', | ||
}, | ||
'&light .CodeMirror-activeline-background': { | ||
background: '#7ff4', | ||
color: 'black', | ||
}, | ||
}), | ||
], | ||
}; | ||
|
||
// Maps several CM5 options to CM6 extensions | ||
export default class CodeMirror5BuiltInOptions { | ||
private activeOptions: string[] = []; | ||
private extensionCompartment: Compartment = new Compartment(); | ||
|
||
public constructor(private editor: EditorView) { | ||
editor.dispatch({ | ||
effects: StateEffect.appendConfig.of(this.extensionCompartment.of([])), | ||
}); | ||
} | ||
|
||
private updateExtensions() { | ||
const extensions = this.activeOptions.map(option => optionToExtension[option]); | ||
this.editor.dispatch({ | ||
effects: this.extensionCompartment.reconfigure(extensions), | ||
}); | ||
} | ||
|
||
public supportsOption(option: string) { | ||
return optionToExtension.hasOwnProperty(option); | ||
} | ||
|
||
public setOption(optionName: string, value: boolean) { | ||
this.activeOptions = this.activeOptions.filter(other => other !== optionName); | ||
|
||
if (value) { | ||
this.activeOptions.push(optionName); | ||
} | ||
|
||
this.updateExtensions(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -91,4 +91,5 @@ activatable | |
titlewrapper | ||
notyf | ||
Notyf | ||
Prec | ||
activeline | ||
Prec |
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.
Adding the
.CodeMirror
class to the editor makes it easier to migrate styles originally intended for CodeMirror 5. It does, however, mean that several CodeMirror 5 styles need to be overridden.