New Class for BufferMappings

This commit is contained in:
frelodev 2024-02-14 15:41:58 +01:00
parent fa6a0b2399
commit 03eda74d78

40
src/mapping.ts Normal file
View file

@ -0,0 +1,40 @@
import * as vscode from 'vscode';
import * as codemp from '../index'; // TODO why won't it work with a custom name???
export class BufferMapping {
buffer: codemp.JsBufferController;
editor: vscode.TextEditor;
constructor(codemp_buffer: codemp.JsBufferController, editor: vscode.TextEditor) {
this.buffer = codemp_buffer;
this.editor = editor;
}
}
export class BufferMappingContainer {
store: BufferMapping[];
constructor() {
this.store = [];
}
put(mapping: BufferMapping) {
this.store.push(mapping);
}
get_by_editor(uri: vscode.Uri) : BufferMapping | null {
for (let mapping of this.store) {
if (mapping.editor.document.uri === uri)
return mapping;
}
return null;
}
get_by_buffer(path: string) : BufferMapping | null {
for (let mapping of this.store) {
if (mapping.buffer.getName() === path)
return mapping;
}
return null;
}
}