aboutsummaryrefslogtreecommitdiff
path: root/code/native
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-07 16:28:30 +0100
committerAleksey Kladov <[email protected]>2018-08-07 16:36:33 +0100
commit2fb854ccdae6f1f12b60441e5c3b283bdc81fb0a (patch)
treeed4f31d31473a2faf8e014907960f855b96cca22 /code/native
parenta04473e2bb95483e84404c57426ee9ed21fa5d6b (diff)
:tada: extend selection
Diffstat (limited to 'code/native')
-rw-r--r--code/native/src/lib.rs32
1 files changed, 30 insertions, 2 deletions
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;
3extern crate libeditor; 3extern crate libeditor;
4 4
5use neon::prelude::*; 5use neon::prelude::*;
6use libeditor::TextRange;
6 7
7pub struct Wrapper { 8pub struct Wrapper {
8 inner: libeditor::File, 9 inner: libeditor::File,
@@ -19,8 +20,8 @@ declare_types! {
19 } 20 }
20 21
21 method syntaxTree(mut cx) { 22 method syntaxTree(mut cx) {
22 let this = cx.this();
23 let tree = { 23 let tree = {
24 let this = cx.this();
24 let guard = cx.lock(); 25 let guard = cx.lock();
25 let wrapper = this.borrow(&guard); 26 let wrapper = this.borrow(&guard);
26 wrapper.inner.syntax_tree() 27 wrapper.inner.syntax_tree()
@@ -29,8 +30,8 @@ declare_types! {
29 } 30 }
30 31
31 method highlight(mut cx) { 32 method highlight(mut cx) {
32 let this = cx.this();
33 let highlights = { 33 let highlights = {
34 let this = cx.this();
34 let guard = cx.lock(); 35 let guard = cx.lock();
35 let wrapper = this.borrow(&guard); 36 let wrapper = this.borrow(&guard);
36 wrapper.inner.highlight() 37 wrapper.inner.highlight()
@@ -51,6 +52,33 @@ declare_types! {
51 52
52 Ok(res.upcast()) 53 Ok(res.upcast())
53 } 54 }
55
56 method extendSelection(mut cx) {
57 let from_offset = cx.argument::<JsNumber>(0)?.value() as u32;
58 let to_offset = cx.argument::<JsNumber>(1)?.value() as u32;
59 let text_range = TextRange::from_to(from_offset.into(), to_offset.into());
60 let extended_range = {
61 let this = cx.this();
62 let guard = cx.lock();
63 let wrapper = this.borrow(&guard);
64 wrapper.inner.extend_selection(text_range)
65 };
66
67 match extended_range {
68 None => Ok(cx.null().upcast()),
69 Some(range) => {
70 let start: u32 = range.start().into();
71 let end: u32 = range.end().into();
72 let start = cx.number(start);
73 let end = cx.number(end);
74 let arr = cx.empty_array();
75 arr.set(&mut cx, 0, start)?;
76 arr.set(&mut cx, 1, end)?;
77 Ok(arr.upcast())
78 }
79 }
80
81 }
54 } 82 }
55 83
56} 84}