feat: jump to other user's cursor

This commit is contained in:
frelodev 2024-09-24 23:27:45 +02:00
parent 2d9dca2b0a
commit 01a91d79ec
3 changed files with 37 additions and 1 deletions

View file

@ -86,6 +86,11 @@
"command": "codemp.sync", "command": "codemp.sync",
"when": "view == codemp-tree-view && viewItem == buffer_active", "when": "view == codemp-tree-view && viewItem == buffer_active",
"group": "inline" "group": "inline"
},
{
"command": "codemp.jump",
"when": "view == codemp-tree-view && viewItem == user",
"group": "inline"
} }
] ]
}, },
@ -168,6 +173,12 @@
"title": "Refresh", "title": "Refresh",
"category": "codemp", "category": "codemp",
"icon": "$(extensions-refresh)" "icon": "$(extensions-refresh)"
},
{
"command": "codemp.jump",
"title": "Jump",
"category": "codemp",
"icon": "$(debug-step-into)"
} }
], ],
"configuration": { "configuration": {

View file

@ -418,6 +418,31 @@ export async function refresh() {
provider.refresh(); provider.refresh();
} }
export async function jump(selected: vscode.TreeItem | undefined){
if (client === null) throw "connect first";
let user;
if (selected !== undefined && selected.label !== undefined) {
if (typeof(selected.label) === 'string') {
user = selected.label;
} else {
user = selected.label.label;
}
}
if(user) user = user.split(' (')[0];//Label on tree also contains Buffer name along with username
else user = await vscode.window.showInputBox({ prompt: "username"});
if (!user) return; // user cancelled with ESC
let user_hl = mapping.colors_cache.get(user);
if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user");
let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer);
if (uri === undefined) {
return vscode.window.showWarningMessage("user is on an untracked buffer: "+ user_hl.buffer);}
let editor = await vscode.window.showTextDocument(uri, { preserveFocus: false });
let range_start: vscode.Position = new vscode.Position(user_hl.startRow, user_hl.startCol);
let range_end: vscode.Position = new vscode.Position(user_hl.endRow, user_hl.endCol);
let cursor_range = new vscode.Range(range_start, range_end);
editor.revealRange(cursor_range, vscode.TextEditorRevealType.InCenter);
}
// This method is called when your extension is deactivated // This method is called when your extension is deactivated
export function deactivate() { export function deactivate() {