mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-21 23:14:49 +01:00
fix: changed follow impl
Co-authored-by: alemi <me@alemi.dev>
This commit is contained in:
parent
dfe0650516
commit
4bc9d27a32
4 changed files with 19 additions and 28 deletions
|
@ -91,11 +91,6 @@
|
|||
"command": "codemp.jump",
|
||||
"when": "view == codemp-tree-view && viewItem == user",
|
||||
"group": "inline"
|
||||
},
|
||||
{
|
||||
"command": "codemp.follow",
|
||||
"when": "view == codemp-tree-view && viewItem == user",
|
||||
"group": "inline"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as codemp from 'codemp';
|
||||
import * as mapping from "../mapping";
|
||||
import { workspace, setWorkspace } from "./workspaces";
|
||||
import { workspace, setWorkspace, follow, setFollow, executeJump } from "./workspaces";
|
||||
import { LOGGER, provider } from '../extension';
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ import { LOGGER, provider } from '../extension';
|
|||
export let client: codemp.Client | null = null;
|
||||
export let workspace_list: string[] = [];
|
||||
export let cursor_disposable: vscode.Disposable | null;
|
||||
let movedByFollow = false;
|
||||
|
||||
export async function connect() {
|
||||
let config = vscode.workspace.getConfiguration('codemp');
|
||||
|
@ -78,6 +79,11 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
mapping.colors_cache.set(event.user, mapp);
|
||||
provider.refresh();
|
||||
}
|
||||
if (follow === event.user) {
|
||||
movedByFollow = true;
|
||||
executeJump(event.user);
|
||||
}
|
||||
|
||||
let editor = mapping.bufferMapper.visible_by_buffer(event.buffer);
|
||||
let refresh = event.buffer != mapp.buffer;
|
||||
mapp.update(event, editor);
|
||||
|
@ -88,9 +94,11 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
let once = true;
|
||||
cursor_disposable = vscode.window.onDidChangeTextEditorSelection(async (event: vscode.TextEditorSelectionChangeEvent) => {
|
||||
if (event.kind == vscode.TextEditorSelectionChangeKind.Command) return; // TODO commands might move cursor too
|
||||
if (!movedByFollow) setFollow(null);
|
||||
else movedByFollow = false;
|
||||
let buf = event.textEditor.document.uri;
|
||||
let selection: vscode.Selection = event.selections[0]
|
||||
let buffer = mapping.bufferMapper.by_editor(buf)
|
||||
let selection: vscode.Selection = event.selections[0];
|
||||
let buffer = mapping.bufferMapper.by_editor(buf);
|
||||
if (buffer === undefined) {
|
||||
if (once) {
|
||||
await controller.send({
|
||||
|
@ -103,6 +111,7 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
|||
}
|
||||
once = false;
|
||||
} else {
|
||||
|
||||
await controller.send({
|
||||
startRow: selection.anchor.line,
|
||||
startCol: selection.anchor.character,
|
||||
|
|
|
@ -6,13 +6,17 @@ import { LOGGER, provider } from '../extension';
|
|||
|
||||
|
||||
export let workspace: codemp.Workspace | null = null;
|
||||
export let doFollow: boolean = false;
|
||||
export let follow: string | null = null;
|
||||
|
||||
|
||||
export function setWorkspace(ws: codemp.Workspace | null) {
|
||||
workspace = ws;
|
||||
}
|
||||
|
||||
export function setFollow(doFollow: string | null) {
|
||||
follow = doFollow;
|
||||
}
|
||||
|
||||
|
||||
export async function jump(selected: vscode.TreeItem | undefined) {
|
||||
if (client === null) return vscode.window.showWarningMessage("Connect first");
|
||||
|
@ -26,6 +30,7 @@ export async function jump(selected: vscode.TreeItem | undefined) {
|
|||
}
|
||||
if (!user) user = await vscode.window.showInputBox({ prompt: "username" });
|
||||
if (!user) return; // user cancelled with ESC
|
||||
setFollow(user);
|
||||
executeJump(user);
|
||||
}
|
||||
|
||||
|
@ -43,23 +48,6 @@ export async function executeJump(user: string) {
|
|||
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() {
|
||||
let bufferName: any = (await vscode.window.showInputBox({ prompt: "path of the buffer to create" }));
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as codemp from 'codemp';
|
|||
import { client, connect, join, refresh, createWorkspace, inviteToWorkspace, listWorkspaces, leave } from './commands/client';
|
||||
import { CodempTreeProvider } from './tree';
|
||||
import * as mapping from './mapping';
|
||||
import { workspace, jump, listBuffers, createBuffer, deleteBuffer, follow } from './commands/workspaces'
|
||||
import { workspace, jump, listBuffers, createBuffer, deleteBuffer } from './commands/workspaces'
|
||||
import { attach, share, sync, apply_changes_to_buffer, detach } from './commands/buffers'
|
||||
|
||||
export let provider = new CodempTreeProvider();
|
||||
|
@ -46,7 +46,6 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
vscode.commands.registerCommand('codemp.sync', sync),
|
||||
vscode.commands.registerCommand('codemp.refresh', refresh),
|
||||
vscode.commands.registerCommand('codemp.jump', jump),
|
||||
vscode.commands.registerCommand('codemp.follow', follow),
|
||||
]) {
|
||||
context.subscriptions.push(cmd);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue