From 03eda74d788909b0dbd8d6af977728b89e4cd79b Mon Sep 17 00:00:00 2001 From: frelodev Date: Wed, 14 Feb 2024 15:41:58 +0100 Subject: [PATCH] New Class for BufferMappings --- src/mapping.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/mapping.ts diff --git a/src/mapping.ts b/src/mapping.ts new file mode 100644 index 0000000..579d2ef --- /dev/null +++ b/src/mapping.ts @@ -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; + } +} \ No newline at end of file