Skip to content

Commit

Permalink
fix selection of inserted text of snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakae committed May 15, 2024
1 parent b8cdc67 commit 8dbc82a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions extension/src/diagram-snippets-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { StpaLspVscodeExtension } from './language-extension';
import { acceptMessageType } from 'sprotty-vscode/lib/lsp';
import { SendDefaultSnippetsAction } from './actions';

/**
* Initializes the diagram snippets webview and handles messages from and to it.
*/
export class DiagramSnippetWebview {

static viewCount = 0;
Expand Down Expand Up @@ -77,7 +80,7 @@ export class DiagramSnippetWebview {
this.disposables.push(this.webview.onDidReceiveMessage(message => this.receiveFromWebview(message)));
/* this.disposables.push(vscode.window.onDidChangeActiveTextEditor(async editor => {
if (editor) {
//TODO: snippets may be needed to be updated
//TODO: if snippets for more than one language exist, check if the current language is supported
}
})); */
await this.ready();
Expand All @@ -100,7 +103,6 @@ export class DiagramSnippetWebview {
this.resolveWebviewReady();
this.sendDiagramIdentifier();

// TODO: guarantee that sprotty webview exist
if (this.extension.clientId) {
// send the snippets saved in the config file to the language server,
// which will send the rendered snippets back to the diagram snippets webview
Expand Down
7 changes: 5 additions & 2 deletions extension/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ export async function handleWorkSpaceEdit(uri: string, text: string, position: v

const activeEditor = vscode.window.activeTextEditor;
if (activeEditor) {
// TODO: endPos is not completly correct. maybe \n must be counted too?
const endPos = textDocument.positionAt(textDocument.offsetAt(position) + text.length);
// count the line breaks to determine the end position
const lineBreaks = text.match(/\n/g);
const lines = lineBreaks ? lineBreaks.length : 1;
const endPos = { line: position.line + lines, character: 0} as vscode.Position;
// select and reveal the inserted text
activeEditor.selections = [new vscode.Selection(position, endPos)];
activeEditor.revealRange(new vscode.Range(position, endPos));
}
Expand Down

0 comments on commit 8dbc82a

Please sign in to comment.