feat: follow

This commit is contained in:
frelodev 2024-10-06 23:58:58 +02:00
parent 2a72104a02
commit dfe0650516
3 changed files with 36 additions and 2 deletions

View file

@ -91,6 +91,11 @@
"command": "codemp.jump", "command": "codemp.jump",
"when": "view == codemp-tree-view && viewItem == user", "when": "view == codemp-tree-view && viewItem == user",
"group": "inline" "group": "inline"
},
{
"command": "codemp.follow",
"when": "view == codemp-tree-view && viewItem == user",
"group": "inline"
} }
] ]
}, },
@ -187,6 +192,13 @@
"category": "codemp", "category": "codemp",
"icon": "$(debug-console-evaluation-input)" "icon": "$(debug-console-evaluation-input)"
} }
,
{
"command": "codemp.follow",
"title": "Follow User",
"category": "codemp",
"icon": "$(debug-console-evaluation-input)"
}
], ],
"configuration": { "configuration": {
"title": "codemp", "title": "codemp",

View file

@ -6,6 +6,7 @@ import { LOGGER, provider } from '../extension';
export let workspace: codemp.Workspace | null = null; export let workspace: codemp.Workspace | null = null;
export let doFollow: boolean = false;
export function setWorkspace(ws: codemp.Workspace | null) { export function setWorkspace(ws: codemp.Workspace | null) {
@ -25,7 +26,10 @@ export async function jump(selected: vscode.TreeItem | undefined) {
} }
if (!user) user = await vscode.window.showInputBox({ prompt: "username" }); if (!user) user = await vscode.window.showInputBox({ prompt: "username" });
if (!user) return; // user cancelled with ESC if (!user) return; // user cancelled with ESC
executeJump(user);
}
export async function executeJump(user: string) {
let user_hl = mapping.colors_cache.get(user); let user_hl = mapping.colors_cache.get(user);
if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user"); if (user_hl === undefined) return vscode.window.showWarningMessage("unknown position of such user");
let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer); let uri = mapping.bufferMapper.uri_by_buffer(user_hl.buffer);
@ -39,6 +43,23 @@ export async function jump(selected: vscode.TreeItem | undefined) {
editor.revealRange(cursor_range, vscode.TextEditorRevealType.InCenter); editor.revealRange(cursor_range, vscode.TextEditorRevealType.InCenter);
} }
export async function follow(selected: vscode.TreeItem | undefined) {
doFollow=!doFollow
if (client === null) return vscode.window.showWarningMessage("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 = await vscode.window.showInputBox({ prompt: "username" });
if (!user) return; // user cancelled with ESC
while(doFollow){
executeJump(user);
}
}
export async function createBuffer() { export async function createBuffer() {
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to create" })); let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to create" }));
@ -62,5 +83,5 @@ export async function deleteBuffer() {
await workspace.delete(bufferName); await workspace.delete(bufferName);
vscode.window.showInformationMessage(`Deleted buffer :${bufferName}`); vscode.window.showInformationMessage(`Deleted buffer :${bufferName}`);
listBuffers(); listBuffers();
} }

View file

@ -3,7 +3,7 @@ import * as codemp from 'codemp';
import { client, connect, join, refresh, createWorkspace, inviteToWorkspace, listWorkspaces, leave } from './commands/client'; import { client, connect, join, refresh, createWorkspace, inviteToWorkspace, listWorkspaces, leave } from './commands/client';
import { CodempTreeProvider } from './tree'; import { CodempTreeProvider } from './tree';
import * as mapping from './mapping'; import * as mapping from './mapping';
import { workspace, jump, listBuffers, createBuffer, deleteBuffer } from './commands/workspaces' import { workspace, jump, listBuffers, createBuffer, deleteBuffer, follow } from './commands/workspaces'
import { attach, share, sync, apply_changes_to_buffer, detach } from './commands/buffers' import { attach, share, sync, apply_changes_to_buffer, detach } from './commands/buffers'
export let provider = new CodempTreeProvider(); export let provider = new CodempTreeProvider();
@ -46,6 +46,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('codemp.sync', sync), vscode.commands.registerCommand('codemp.sync', sync),
vscode.commands.registerCommand('codemp.refresh', refresh), vscode.commands.registerCommand('codemp.refresh', refresh),
vscode.commands.registerCommand('codemp.jump', jump), vscode.commands.registerCommand('codemp.jump', jump),
vscode.commands.registerCommand('codemp.follow', follow),
]) { ]) {
context.subscriptions.push(cmd); context.subscriptions.push(cmd);
} }