Fix RSLang editing

This commit is contained in:
IRBorisov 2023-08-27 19:48:08 +03:00
parent be360312d4
commit 0134af6b57
2 changed files with 21 additions and 19 deletions

View File

@ -21,5 +21,11 @@ const darkTheme = EditorView.baseTheme(bracketsDarkT);
const lightTheme = EditorView.baseTheme(bracketsLightT);
export function ccBracketMatching(darkMode: boolean) {
return [bracketMatching({ renderMatch: bracketRender }), darkMode ? darkTheme : lightTheme];
return [
bracketMatching({
renderMatch: bracketRender,
brackets:'{}[]()'
}),
darkMode ? darkTheme : lightTheme
];
}

View File

@ -51,15 +51,19 @@ export class TextWrapper {
}
envelopeWith(left: string, right: string) {
const hasSelection = this.ref.view.state.selection.main.from !== this.ref.view.state.selection.main.to
const newSelection = hasSelection ? {
anchor: this.ref.view.state.selection.main.from,
head: this.ref.view.state.selection.main.to + left.length + right.length
} : {
anchor: this.ref.view.state.selection.main.to + left.length + right.length - 1,
}
this.ref.view.dispatch({
changes: [
{from: this.ref.view.state.selection.main.from, insert: left},
{from: this.ref.view.state.selection.main.to, insert: right}
],
selection: {
anchor: this.ref.view.state.selection.main.from,
head: this.ref.view.state.selection.main.to + left.length + right.length
}
selection: newSelection
});
}
@ -89,11 +93,6 @@ export class TextWrapper {
} else {
this.envelopeWith('I{(σ, γ) | σ:∈X1; γ:=F1[σ]; P1[σ, γ]', '}');
}
this.ref.view.dispatch({
selection: {
anchor: this.ref.view.state.selection.main.from + 2,
}
});
return true;
}
case TokenID.NT_RECURSIVE_FULL: {
@ -102,11 +101,6 @@ export class TextWrapper {
} else {
this.envelopeWith('R{ξ:=D1 | F1[ξ]≠∅ | ξF1[ξ]', '}');
}
this.ref.view.dispatch({
selection: {
anchor: this.ref.view.state.selection.main.from + 2,
}
});
return true;
}
case TokenID.BIGPR: this.envelopeWith('Pr1(', ')'); return true;
@ -128,11 +122,13 @@ export class TextWrapper {
}
case TokenID.PUNC_SL: {
this.envelopeWith('[', ']');
if (hasSelection) {
this.ref.view.dispatch({
selection: {
anchor: hasSelection ? this.ref.view.state.selection.main.to: this.ref.view.state.selection.main.from + 1,
}
});
}
return true;
}
case TokenID.BOOLEAN: {