Sitelet https://web.archive.org/web/20250725144604/https://github.com/marktext/marktext/pull/3129
Skip to content

Code Editor basic support for: undo, redo, find, replace #3129

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

mitchcapper
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Breaking changes? no
Deprecations? no
New tests added? no
Fixed tickets Adds some of #2188 in basic form
License MIT

Description

Adds some of the features requested from #2188

This is a bit of a quick hack together so not properly implemented to use the marktext search box, instead use the codeMirror one with some styling. This also adds an undocumented, keybind of alt+g to go to jump to line number. Note if you bind something to alt+g in marktext then this will not fire.

@mitchcapper mitchcapper force-pushed the sourcecode_editor_find_undo_redo_fixes_pr branch from e17f0c9 to 417d185 Compare March 16, 2022 22:56
}
.CodeMirror-search-label{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this empty CSS key/body.


}
.CodeMirror-dialog {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please check the styling with dark themes, it's a bit odd. Also, OneDark has dark font color on dark background.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the control was essentially un-themed. Would you prefer legibility is working for both, or to actually flip the theme based on marktext?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flipping the theme would be great. I think we use two different themes based whether MarkTexts theme is light or darkish. Maybe we can use CSS selectors to differentiate colors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I assumed CSS light/dark overall would be the way to go. Will update.

import 'codemirror/addon/search/searchcursor'
import 'codemirror/addon/dialog/dialog'
import 'codemirror/addon/search/search'
import 'codemirror/addon/search/jump-to-line'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed for search or only for the Alt+G shortcut? Please remove the dependency if it's not necessary for seach as it may conflict with other functions (later).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only jump-to-line is for alt+g, the rest is required for search. I expect in the long term that the code editor will get more 'native' search removing the dialog need. As far as I know the addons should not cause any code conflict as they are siloed into their own class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core problem that the feature is undocumented and it doesn't for for preview mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that was largely why I was leaving it undocumented too, was it only worked in the code editor. To confirm you just want jump-to-line removed correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

@@ -993,13 +993,13 @@ export default {
},

handleUndo () {
if (this.editor) {
if (this.editor && this.sourceCode === false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this.sourceCode === false to !this.sourceCode

this.editor.undo()
}
},

handleRedo () {
if (this.editor) {
if (this.editor && this.sourceCode === false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this.sourceCode === false to !this.sourceCode

@@ -1077,6 +1077,7 @@ export default {
},

handleFindAction (action) {
if (this.sourceCode) { return }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line to the body (preferred) or remove brackets around return.

},

docClick () {
if (this.editor && this.sourceCode) { this.editor.execCommand('clearSearch') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the body in a new line.

@@ -245,6 +261,49 @@ export default {
this.tabId = null // invalidate tab id
}
},
handleUndo () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep spacing (new lines) between methods. You could group e.g. undo/redo etc if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants