From 2fb854ccdae6f1f12b60441e5c3b283bdc81fb0a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Aug 2018 18:28:30 +0300 Subject: :tada: extend selection --- code/native/src/lib.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'code/native/src/lib.rs') diff --git a/code/native/src/lib.rs b/code/native/src/lib.rs index aae7ad2f3..cb304a141 100644 --- a/code/native/src/lib.rs +++ b/code/native/src/lib.rs @@ -3,6 +3,7 @@ extern crate neon; extern crate libeditor; use neon::prelude::*; +use libeditor::TextRange; pub struct Wrapper { inner: libeditor::File, @@ -19,8 +20,8 @@ declare_types! { } method syntaxTree(mut cx) { - let this = cx.this(); let tree = { + let this = cx.this(); let guard = cx.lock(); let wrapper = this.borrow(&guard); wrapper.inner.syntax_tree() @@ -29,8 +30,8 @@ declare_types! { } method highlight(mut cx) { - let this = cx.this(); let highlights = { + let this = cx.this(); let guard = cx.lock(); let wrapper = this.borrow(&guard); wrapper.inner.highlight() @@ -51,6 +52,33 @@ declare_types! { Ok(res.upcast()) } + + method extendSelection(mut cx) { + let from_offset = cx.argument::(0)?.value() as u32; + let to_offset = cx.argument::(1)?.value() as u32; + let text_range = TextRange::from_to(from_offset.into(), to_offset.into()); + let extended_range = { + let this = cx.this(); + let guard = cx.lock(); + let wrapper = this.borrow(&guard); + wrapper.inner.extend_selection(text_range) + }; + + match extended_range { + None => Ok(cx.null().upcast()), + Some(range) => { + let start: u32 = range.start().into(); + let end: u32 = range.end().into(); + let start = cx.number(start); + let end = cx.number(end); + let arr = cx.empty_array(); + arr.set(&mut cx, 0, start)?; + arr.set(&mut cx, 1, end)?; + Ok(arr.upcast()) + } + } + + } } } -- cgit v1.2.3