chore: allow creating user deco from just name

This commit is contained in:
əlemi 2024-09-25 05:10:04 +02:00
parent 117a540d6f
commit 74a5dc2ac0
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -10,7 +10,6 @@ class BufferMapper {
this.editorToBufferMapping.set(uri, buffer); this.editorToBufferMapping.set(uri, buffer);
} }
public uri_by_buffer(name: string): vscode.Uri | undefined { public uri_by_buffer(name: string): vscode.Uri | undefined {
let uri = this.bufferToEditorMapping.get(name); let uri = this.bufferToEditorMapping.get(name);
return uri; return uri;
@ -39,22 +38,20 @@ export class UserDecoration {
decoration: vscode.TextEditorDecorationType | null; decoration: vscode.TextEditorDecorationType | null;
color: string; color: string;
buffer: string; buffer: string;
startRow : number; startRow : number
startCol : number; startCol : number;
endRow : number; endRow : number;
endCol : number; endCol : number;
public constructor(name: string) {
public constructor(event: codemp.Cursor) { let hash = codemp.hash(name);
let hash = codemp.hash(event.user || "anon");
this.color = colors[Math.abs(hash) % colors.length]; this.color = colors[Math.abs(hash) % colors.length];
this.decoration = null; this.decoration = null;
this.buffer = event.buffer; this.buffer = "";
this.startRow = event.startRow; this.startRow = 0;
this.startCol = event.startCol; this.startCol = 0;
this.endRow = event.endRow; this.endRow = 0;
this.endCol = event.endCol; this.endCol = 0;
} }
// TODO can we avoid disposing and recreating the decoration type every time? // TODO can we avoid disposing and recreating the decoration type every time?
@ -100,3 +97,4 @@ const colors = [
]; ];
export const colors_cache: Map<string, UserDecoration> = new Map(); export const colors_cache: Map<string, UserDecoration> = new Map();