mirror of
https://github.com/hexedtech/codemp-vscode.git
synced 2024-11-22 15:34:49 +01:00
feat: display the users current cursor position in the tree view
This commit is contained in:
parent
c6c2ac7558
commit
f5d2091891
3 changed files with 20 additions and 8 deletions
|
@ -67,15 +67,15 @@ export async function join(selected: vscode.TreeItem | undefined) {
|
||||||
LOGGER.warn(`Skipping cursor event without user: ${event}`)
|
LOGGER.warn(`Skipping cursor event without user: ${event}`)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let mapp = mapping.colors_cache.get(event.user)
|
let mapp = mapping.colors_cache.get(event.user);
|
||||||
if (mapp === undefined) { // first time we see this user
|
if (mapp === undefined) { // first time we see this user
|
||||||
mapp = new mapping.UserDecoration(event);
|
mapp = new mapping.UserDecoration(event);
|
||||||
mapping.colors_cache.set(event.user, mapp);
|
mapping.colors_cache.set(event.user, mapp);
|
||||||
|
provider.refresh();
|
||||||
}
|
}
|
||||||
let editor = mapping.bufferMapper.by_buffer(event.buffer);
|
let editor = mapping.bufferMapper.by_buffer(event.buffer);
|
||||||
if (editor !== undefined) {
|
mapp.update(event,editor);
|
||||||
mapp.apply(editor, event);
|
/*if(event.buffer!=mapp.buffer) */provider.refresh();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -166,6 +166,7 @@ export async function share(selected: vscode.TreeItem | undefined) {
|
||||||
if (locks.get(buffer_name)) { return }
|
if (locks.get(buffer_name)) { return }
|
||||||
if (event.document.uri !== file_uri) return; // ?
|
if (event.document.uri !== file_uri) return; // ?
|
||||||
for (let change of event.contentChanges) {
|
for (let change of event.contentChanges) {
|
||||||
|
console.log(event.contentChanges);
|
||||||
LOGGER.debug(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
LOGGER.debug(`onDidChangeTextDocument(event: [${change.rangeOffset}, ${change.text}, ${change.rangeOffset + change.rangeLength}])`);
|
||||||
await buffer.send({
|
await buffer.send({
|
||||||
start: change.rangeOffset,
|
start: change.rangeOffset,
|
||||||
|
|
|
@ -24,34 +24,40 @@ class BufferMapper {
|
||||||
public static instance = new BufferMapper();
|
public static instance = new BufferMapper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO rename maybe? mapper.bufferMapper is a little bit overkill
|
// TODO rename maybe? mapper.bufferMapper is a little bit overkill
|
||||||
export let bufferMapper = BufferMapper.instance;
|
export let bufferMapper = BufferMapper.instance;
|
||||||
|
|
||||||
export class UserDecoration {
|
export class UserDecoration {
|
||||||
decoration: vscode.TextEditorDecorationType | null;
|
decoration: vscode.TextEditorDecorationType | null;
|
||||||
color: string;
|
color: string;
|
||||||
|
buffer: string;
|
||||||
|
|
||||||
|
|
||||||
public constructor(event: codemp.Cursor) {
|
public constructor(event: codemp.Cursor) {
|
||||||
let hash = codemp.hash(event.user || "anon");
|
let hash = codemp.hash(event.user || "anon");
|
||||||
this.color = colors[hash % colors.length];
|
this.color = colors[hash % colors.length];
|
||||||
this.decoration = null;
|
this.decoration = null;
|
||||||
|
this.buffer = event.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO can we avoid disposing and recreating the decoration type every time?
|
// TODO can we avoid disposing and recreating the decoration type every time?
|
||||||
public apply(editor: vscode.TextEditor, event: codemp.Cursor) {
|
public update(event: codemp.Cursor, editor?: vscode.TextEditor) {
|
||||||
|
this.buffer=event.buffer;
|
||||||
if (this.decoration == null) {
|
if (this.decoration == null) {
|
||||||
this.decoration = vscode.window.createTextEditorDecorationType({
|
this.decoration = vscode.window.createTextEditorDecorationType({
|
||||||
borderWidth: '1px',
|
borderWidth: '1px',
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
borderColor: this.color,
|
borderColor: this.color,
|
||||||
backgroundColor: this.color + '44', // add alpha
|
backgroundColor: this.color + '44', // add alpha
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const range_start: vscode.Position = new vscode.Position(event.startRow, event.startCol); // -1?
|
const range_start: vscode.Position = new vscode.Position(event.startRow, event.startCol); // -1?
|
||||||
const range_end: vscode.Position = new vscode.Position(event.endRow, event.endCol); // -1? idk if this works it's kinda funny, should test with someone with a working version of codemp
|
const range_end: vscode.Position = new vscode.Position(event.endRow, event.endCol); // -1? idk if this works it's kinda funny, should test with someone with a working version of codemp
|
||||||
const decorationRange = new vscode.Range(range_start, range_end);
|
const decorationRange = new vscode.Range(range_start, range_end);
|
||||||
editor.setDecorations(this.decoration, [decorationRange]);
|
if(editor !== undefined) editor.setDecorations(this.decoration, [decorationRange]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public clear() {
|
public clear() {
|
||||||
|
|
|
@ -41,8 +41,13 @@ export class CodempTreeProvider implements vscode.TreeDataProvider<CodempTreeIte
|
||||||
|
|
||||||
case Type.UserList:
|
case Type.UserList:
|
||||||
let out = [];
|
let out = [];
|
||||||
for (let x of colors_cache.keys()){
|
|
||||||
out.push(new CodempTreeItem(x, Type.User, false));
|
/*colors_cache.forEach(function(x){
|
||||||
|
out.push(new CodempTreeItem(x.color, Type.User, false));
|
||||||
|
});*/
|
||||||
|
for (let x of colors_cache){
|
||||||
|
|
||||||
|
out.push(new CodempTreeItem(`${x[0]}(${x[1].buffer})`, Type.User, false));
|
||||||
};
|
};
|
||||||
return out;
|
return out;
|
||||||
case Type.Buffer:
|
case Type.Buffer:
|
||||||
|
|
Loading…
Reference in a new issue