Skip to content

Commit

Permalink
fix: codemirror can not select all
Browse files Browse the repository at this point in the history
  • Loading branch information
drl990114 committed Apr 26, 2024
1 parent 12c7272 commit af7c90b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/editor/codemirror/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ class MfCodemirrorView {
const targetPos = this.getPos() + (dir < 0 ? 0 : this.node.nodeSize)
const selection = Selection.near(this.view.state.doc.resolve(targetPos), dir)

if (dir === 1 && exitCode(this.view.state, this.view.dispatch)) {
this.view.focus()
return true
}

this.view.dispatch(this.view.state.tr.setSelection(selection).scrollIntoView())
this.view.focus()
return true
Expand Down
1 change: 1 addition & 0 deletions src/editor/extensions/CodeMirror/codemirror-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class LineCodeMirrorExtension extends NodeExtension<CodeMirrorExtensionOp
defining: true,
...override,
code: true,
selectable: true,
attrs: {
...extra.defaults(),
language: { default: '' },
Expand Down
11 changes: 8 additions & 3 deletions src/editor/extensions/CodeMirror/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import {
keymap,
highlightSpecialChars,
drawSelection,
highlightActiveLine,
dropCursor,
rectangularSelection,
Expand Down Expand Up @@ -111,11 +110,17 @@ export const basicSetup: Extension = (() => [
/// style](#language.defaultHighlightStyle).
export const minimalSetup: Extension = (() => [
dropCursor(),

lineNumbers(),
highlightSpecialChars(),
history(),
drawSelection(),
rectangularSelection(),
indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
bracketMatching(),
closeBrackets(),
autocompletion(),
crosshairCursor(),
highlightSelectionMatches(),
keymap.of([
...closeBracketsKeymap,
...defaultKeymap,
Expand Down
5 changes: 4 additions & 1 deletion src/editor/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { IframeExtension } from './Iframe'
import { SlashMenuExtension } from './SlashMenu'
import { PlaceholderExtension } from './Placeholder'
import { ClipboardExtension } from './Clipboard'
import { minimalSetup } from './CodeMirror/setup'

// import { TableExtension } from './ReactTables';

Expand Down Expand Up @@ -76,7 +77,9 @@ function extensions({ handleViewImgSrcUrl }: ExtensionsOptions): any[] {
new LineBlockquoteExtension(),
new LineHeadingExtension({}),
new LineListExtension(),
new LineCodeMirrorExtension({}),
new LineCodeMirrorExtension({
extensions: [minimalSetup]
}),
new LineTableExtension({ resizable: false }),
new LineTableRowExtension(),
new LineTableCellExtension(),
Expand Down
4 changes: 3 additions & 1 deletion src/editor/theme/WysiwygThemeWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,6 @@ export const WysiwygThemeWrapper = styled.div.attrs<WarpperProps>((p) => p)`
& .cm-editor {
height: auto;
padding: 8px 12px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
Expand Down Expand Up @@ -733,6 +732,9 @@ export const WysiwygThemeWrapper = styled.div.attrs<WarpperProps>((p) => p)`
}
.cm-lineNumbers .cm-gutterElement {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: ${(props) => props.theme.bgColor};
}
Expand Down
10 changes: 8 additions & 2 deletions src/playground/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const defaultContent = [
![img](https://www.gstatic.com/images/branding/googlelogo/svg/googlelogo_clr_74x24px.svg)
a
\`\`\`js
console.log('Hello MarkFlowy')
\`\`\`
`.trim(),
].join("\n")

Expand Down Expand Up @@ -54,7 +57,10 @@ const headingContent = `
`

const htmlContent = `
[version-badge]: https://img.shields.io/github/v/release/drl990114/MarkFlowy?label=version&style=flat-square
<mark>Mark Tag</mark>.
this is a img inline <img src="https://www.gstatic.com/images/branding/googlelogo/svg/googlelogo_clr_74x24px.svg" />.
`

export const contentMap: { [key: string]: string } = {
Expand Down

0 comments on commit af7c90b

Please sign in to comment.