diff --git a/helix-term/src/commands/engine.rs b/helix-term/src/commands/engine.rs index 2d92096dc..e74f52c4a 100644 --- a/helix-term/src/commands/engine.rs +++ b/helix-term/src/commands/engine.rs @@ -1,6 +1,6 @@ use fuzzy_matcher::FuzzyMatcher; use helix_core::{graphemes, Tendril, Selection}; -use helix_view::{document::Mode, Document, DocumentId, Editor, editor::Action}; +use helix_view::{document::Mode, Document, DocumentId, Editor, editor::Action, extension::document_id_to_usize}; use once_cell::sync::Lazy; use steel::{ gc::unsafe_erased_pointers::CustomReference, @@ -556,6 +556,7 @@ fn configure_engine() -> std::rc::Rcdoc-id", get_document_id); + engine.register_fn("doc-id->usize", document_id_to_usize); engine.register_fn("editor-switch!", switch); engine.register_fn("editor-set-focus!", Editor::focus); engine.register_fn("editor-mode", editor_get_mode); @@ -969,6 +970,8 @@ fn get_document_id(editor: &mut Editor, view_id: helix_view::ViewId) -> Document editor.tree.get(view_id).doc } + + // Get the document from the document id - TODO: Add result type here fn get_document(editor: &mut Editor, doc_id: DocumentId) -> &Document { editor.documents.get(&doc_id).unwrap() diff --git a/helix-view/src/extension.rs b/helix-view/src/extension.rs index 6aaa290e4..16b7773f9 100644 --- a/helix-view/src/extension.rs +++ b/helix-view/src/extension.rs @@ -9,3 +9,7 @@ impl Custom for crate::graphics::CursorKind {} impl Custom for DocumentId {} impl Custom for ViewId {} impl CustomReference for Document {} + +pub fn document_id_to_usize(doc_id: &DocumentId) -> usize { + doc_id.0.into() +} \ No newline at end of file