mirror of
https://github.com/stablyai/orca.git
synced 2026-10-12 08:02:37 +00:00
fix: skip doc link auto-convert while cursor is inside the brackets
The appendTransaction plugin was converting [[s]] immediately on the first keystroke inside [[]]. Now it checks whether the cursor sits between [[ and ]] and skips the match if so, letting the user finish typing before the conversion fires. Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -73,6 +73,7 @@ export const MarkdownDocLink = Node.create({
|
||||
key: docLinkAutoConvertKey,
|
||||
appendTransaction(_transactions, _oldState, newState) {
|
||||
const { tr } = newState
|
||||
const cursor = newState.selection.from
|
||||
let modified = false
|
||||
|
||||
newState.doc.descendants((node, pos) => {
|
||||
@@ -90,11 +91,15 @@ export const MarkdownDocLink = Node.create({
|
||||
|
||||
const from = pos + match.index
|
||||
const to = from + match[0].length
|
||||
const docLinkNode = nodeType.create({ target })
|
||||
|
||||
// Why: earlier replacements shift positions. Map through the
|
||||
// transaction's current mapping so subsequent matches land at
|
||||
// the correct offset.
|
||||
// Why: skip matches where the cursor sits between [[ and ]].
|
||||
// The user is still typing the target — converting now would
|
||||
// swallow their in-progress text into an atomic node.
|
||||
if (cursor > from && cursor < to) {
|
||||
continue
|
||||
}
|
||||
|
||||
const docLinkNode = nodeType.create({ target })
|
||||
tr.replaceWith(tr.mapping.map(from), tr.mapping.map(to), docLinkNode)
|
||||
modified = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user