Fixes #111
This commit is contained in:
parent
bb6bf289d9
commit
2eff823a5d
@ -15,8 +15,12 @@ function keyBindingForQuote(
|
|||||||
right: string,
|
right: string,
|
||||||
): KeyBinding {
|
): KeyBinding {
|
||||||
return {
|
return {
|
||||||
key: quote,
|
any: (target, event): boolean => {
|
||||||
run: (target): boolean => {
|
// Moving this check here rather than using the regular "key" property because
|
||||||
|
// for some reason the "ä" key is not recognized as a quote key by CodeMirror.
|
||||||
|
if (event.key !== quote) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const cursorPos = target.state.selection.main.from;
|
const cursorPos = target.state.selection.main.from;
|
||||||
const chBefore = target.state.sliceDoc(cursorPos - 1, cursorPos);
|
const chBefore = target.state.sliceDoc(cursorPos - 1, cursorPos);
|
||||||
|
|
||||||
@ -34,13 +38,13 @@ function keyBindingForQuote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ok, still here, let's use a smart quote
|
// Ok, still here, let's use a smart quote
|
||||||
let quote = right;
|
let q = right;
|
||||||
if (/\W/.exec(chBefore) && !/[!\?,\.\-=“]/.exec(chBefore)) {
|
if (/\W/.exec(chBefore) && !/[!\?,\.\-=“]/.exec(chBefore)) {
|
||||||
quote = left;
|
q = left;
|
||||||
}
|
}
|
||||||
target.dispatch({
|
target.dispatch({
|
||||||
changes: {
|
changes: {
|
||||||
insert: quote,
|
insert: q,
|
||||||
from: cursorPos,
|
from: cursorPos,
|
||||||
},
|
},
|
||||||
selection: {
|
selection: {
|
||||||
|
Loading…
Reference in New Issue
Block a user