use our own input method in vscode
The lean one was annoying for \{...}
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as vscode from "vscode";
|
||||
import { exec } from "child_process";
|
||||
import path from "path";
|
||||
import { ABBREV } from "./abbrev";
|
||||
|
||||
interface FC {
|
||||
file: string;
|
||||
@@ -22,6 +23,45 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
const diagnosticCollection =
|
||||
vscode.languages.createDiagnosticCollection("newt");
|
||||
|
||||
vscode.workspace.onDidChangeTextDocument((event) => {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor || event.document !== editor.document) return;
|
||||
|
||||
const changes = event.contentChanges;
|
||||
if (changes.length === 0) return;
|
||||
|
||||
const lastChange = changes[changes.length - 1];
|
||||
const text = lastChange.text;
|
||||
|
||||
// Check if the last change is a potential shortcut trigger
|
||||
if (!text || !" ')\\".includes(text)) return;
|
||||
|
||||
const document = editor.document;
|
||||
const position = lastChange.range.end;
|
||||
const lineText = document.lineAt(position.line).text;
|
||||
const start = Math.max(0, position.character - 10);
|
||||
const snippet = lineText.slice(start, position.character);
|
||||
console.log(`change '${text}' snippet ${snippet}`)
|
||||
const m = snippet.match(/(\\[^ ]+)$/);
|
||||
if (m) {
|
||||
const cand = m[0];
|
||||
console.log('cand', cand);
|
||||
const replacement = ABBREV[cand];
|
||||
console.log('repl', replacement);
|
||||
if (replacement) {
|
||||
const range = new vscode.Range(
|
||||
position.line,
|
||||
position.character - cand.length,
|
||||
position.line,
|
||||
position.character
|
||||
);
|
||||
editor.edit((editBuilder) => {
|
||||
editBuilder.replace(range, replacement);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function checkDocument(document: vscode.TextDocument) {
|
||||
const fileName = document.fileName;
|
||||
// Is there a better way to do this? It will get fussy with quoting and all plus it's not visible to the user.
|
||||
|
||||
Reference in New Issue
Block a user