|
|
@@ -173,6 +173,22 @@ export function createToggleRule(
|
|
|
if (text !== lastChar) return false
|
|
|
if (!isTextBlock(view.state, from)) return false
|
|
|
|
|
|
+ // Skip-over: jump past a matching closing delimiter character
|
|
|
+ // one at a time. Runs before the prefix/space checks so the
|
|
|
+ // cursor can advance through an existing closing pair.
|
|
|
+ if (from === to) {
|
|
|
+ const next = state.doc.textBetween(from, from + 1)
|
|
|
+ if (next === lastChar) {
|
|
|
+ log.debug("toggle skip-over", { delimiter, char: lastChar })
|
|
|
+ const tr = state.tr.setSelection(
|
|
|
+ TextSelection.create(state.doc, from + 1),
|
|
|
+ )
|
|
|
+ view.dispatch(tr)
|
|
|
+ view.focus()
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Check if previous chars match the delimiter prefix
|
|
|
const prevChars = state.doc.textBetween(
|
|
|
Math.max(0, from - prefix.length),
|
|
|
@@ -180,14 +196,14 @@ export function createToggleRule(
|
|
|
)
|
|
|
if (prevChars !== prefix) return false
|
|
|
|
|
|
- // Word boundary check for the last character
|
|
|
- if (options?.wordBoundary) {
|
|
|
- const before = state.doc.textBetween(
|
|
|
- Math.max(0, from - prefix.length - 1),
|
|
|
- from - prefix.length,
|
|
|
- )
|
|
|
- if (before && /\w/.test(before)) return false
|
|
|
- }
|
|
|
+ // Only auto-close when preceded by whitespace or start-of-text.
|
|
|
+ // This prevents auto-closing mid-word (e.g. "text**" should not
|
|
|
+ // become "text****") or right after a completed pair.
|
|
|
+ const before = state.doc.textBetween(
|
|
|
+ Math.max(0, from - prefix.length - 1),
|
|
|
+ from - prefix.length,
|
|
|
+ )
|
|
|
+ if (before && !/^\s$/.test(before)) return false
|
|
|
|
|
|
// handleTextInput fires one character at a time, so by the time
|
|
|
// both ** are typed any prior selection is already collapsed.
|
|
|
@@ -252,6 +268,9 @@ export const doubleAsteriskRule: AutoCloseRule = createToggleRule("**")
|
|
|
/** Auto-close ~~ (double tilde โ strikethrough) */
|
|
|
export const doubleTildeRule: AutoCloseRule = createToggleRule("~~")
|
|
|
|
|
|
+/** Auto-close ^^ (double caret โ highlight) */
|
|
|
+export const doubleCaretRule: AutoCloseRule = createToggleRule("^^")
|
|
|
+
|
|
|
/**
|
|
|
* Auto-close $ for inline math and $$ โ math_block conversion.
|
|
|
*
|
|
|
@@ -368,3 +387,10 @@ export const singleUnderscoreRule: AutoCloseRule = {
|
|
|
return true
|
|
|
},
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Redirect spaces typed inside a toggle pair (e.g. inside **text**)
|
|
|
+ * to after the closing delimiter. If the next character is typed,
|
|
|
+ * both the space and the character move back into the pair.
|
|
|
+ */
|
|
|
+// (removed โ revisit later)
|