Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default class Home extends React.Component {
},
});

this.caretRegistration = this.componentRelay.registerCaretHandler(
ComponentRelay.createTextareaCaretHandler(this.editor)
);

this.componentRelay.streamContextItem((note) => {
this.note = note;

Expand All @@ -161,6 +165,8 @@ export default class Home extends React.Component {
'spellcheck',
JSON.stringify(note.content.spellcheck)
);

this.caretRegistration.notifyTextLoaded();
});
}

Expand Down
4 changes: 4 additions & 0 deletions packages/com.sncommunity.markdown-math/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ document.addEventListener('DOMContentLoaded', function (event) {
},
})

const caretRegistration = componentRelay.registerCaretHandler(ComponentRelay.createTextareaCaretHandler(editor))

// The textarea decorator wraps the textarea in the element that scrolls
componentRelay.registerScrollContainer(editor.closest('.ldt'), {
moveCaretToEnd: () => {
Expand All @@ -40,6 +42,8 @@ document.addEventListener('DOMContentLoaded', function (event) {
window.upmath.updateText()

editor.setAttribute('spellcheck', JSON.stringify(workingNote.content.spellcheck))

caretRegistration.notifyTextLoaded()
})

editor.addEventListener('input', function (event) {
Expand Down
3 changes: 3 additions & 0 deletions packages/com.sncommunity.minimal-markdown/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
let workingNote, clientData
let lastValue, lastUUID
let editor
let caretRegistration
let ignoreTextChange = false
let initialLoad = true

Expand Down Expand Up @@ -78,6 +79,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
if (initialLoad) {
initialLoad = false
editor.getDoc().clearHistory()
caretRegistration.notifyTextLoaded()
}

editor.setOption('spellcheck', workingNote.content.spellcheck)
Expand All @@ -92,6 +94,7 @@ document.addEventListener('DOMContentLoaded', function (event) {
inputStyle: getInputStyleForEnvironment(),
})
editor.setSize(undefined, '100%')
caretRegistration = componentRelay.registerCaretHandler(ComponentRelay.createCodeMirrorCaretHandler(editor))

editor.on('change', function () {
if (ignoreTextChange) {
Expand Down
19 changes: 19 additions & 0 deletions packages/org.standardnotes.advanced-markdown-editor/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ document.addEventListener('DOMContentLoaded', function () {
let lastValue, lastUUID, clientData
let renderNote = false
let showingUnsafeContentAlert = false
let caretRegistration
let notifyScrollContentChange

const componentRelay = new ComponentRelay({
Expand Down Expand Up @@ -102,6 +103,8 @@ document.addEventListener('DOMContentLoaded', function () {
} else if (window.easymde.isPreviewActive()) {
window.easymde.togglePreview()
}

caretRegistration.notifyTextLoaded()
registerScrollContainer(mode === 'preview')
}
})
Expand Down Expand Up @@ -219,6 +222,22 @@ document.addEventListener('DOMContentLoaded', function () {
scrollCursorIntoView(editor)
})

const codeMirrorCaretHandler = ComponentRelay.createCodeMirrorCaretHandler(window.easymde.codemirror)
caretRegistration = componentRelay.registerCaretHandler({
...codeMirrorCaretHandler,
restore: (offset) => {
if (window.easymde.isPreviewActive()) {
if (offset !== undefined) {
const editor = window.easymde.codemirror
editor.setCursor(editor.posFromIndex(offset))
}
return true
}

return codeMirrorCaretHandler.restore(offset)
},
})

// CodeMirror sizes its content area through style changes, which the relay doesn't observe
window.easymde.codemirror.on('update', () => notifyScrollContentChange?.())
registerScrollContainer(false)
Expand Down
3 changes: 3 additions & 0 deletions packages/org.standardnotes.code-editor/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ document.addEventListener('DOMContentLoaded', function () {
let workingNote, clientData
let lastValue, lastUUID
let editor, select
let caretRegistration
let ignoreTextChange = false
let initialLoad = true

Expand Down Expand Up @@ -112,6 +113,7 @@ document.addEventListener('DOMContentLoaded', function () {
if (initialLoad) {
initialLoad = false
editor.getDoc().clearHistory()
caretRegistration.notifyTextLoaded()
}

editor.setOption('spellcheck', workingNote.content.spellcheck)
Expand All @@ -133,6 +135,7 @@ document.addEventListener('DOMContentLoaded', function () {
inputStyle: getInputStyleForEnvironment(),
})
editor.setSize('100%', '100%')
caretRegistration = componentRelay.registerCaretHandler(ComponentRelay.createCodeMirrorCaretHandler(editor))

createSelectElements()

Expand Down