on master help sign in
View tree implementation: render multiple split views.

Cursors are still a bit buggy and we should render in focus statusbar differently than in the other pane.

commit448c1abba04e11f77e53629dc06fe47619a741d4 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 3 Feb 2021, 19:36 (6 years ago) parent2bea5db
9 files changed+238−207
Cargo.lock+90−72 helix-term/src/application.rs+11−8 helix-term/src/commands.rs+54−57 helix-term/src/ui/editor.rs+34−16 helix-term/src/ui/mod.rs+28−28 helix-view/Cargo.toml+2 helix-view/src/editor.rs+13−21 helix-view/src/lib.rs+1 helix-view/src/view.rs+5−5
Cargo.lock+90−72
@@ -11,9 +11,9 @@ dependencies = [
1111
1212[[package]]
1313name = "anyhow"
14−version = "1.0.37"
14+version = "1.0.38"
1515source = "registry+https://github.com/rust-lang/crates.io-index"
16−checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86"
16+checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
1717
1818[[package]]
1919name = "async-channel"
@@ -321,9 +321,9 @@ dependencies = [
321321
322322[[package]]
323323name = "dirs-sys-next"
324−version = "0.1.1"
324+version = "0.1.2"
325325source = "registry+https://github.com/rust-lang/crates.io-index"
326−checksum = "99de365f605554ae33f115102a02057d4fc18b01f3284d6870be0938743cfe7d"
326+checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
327327dependencies = [
328328 "libc",
329329 "redox_users",
@@ -388,9 +388,9 @@ dependencies = [
388388
389389[[package]]
390390name = "futures"
391−version = "0.3.9"
391+version = "0.3.12"
392392source = "registry+https://github.com/rust-lang/crates.io-index"
393−checksum = "c70be434c505aee38639abccb918163b63158a4b4bb791b45b7023044bdc3c9c"
393+checksum = "da9052a1a50244d8d5aa9bf55cbc2fb6f357c86cc52e46c62ed390a7180cf150"
394394dependencies = [
395395 "futures-channel",
396396 "futures-core",
@@ -403,9 +403,9 @@ dependencies = [
403403
404404[[package]]
405405name = "futures-channel"
406−version = "0.3.9"
406+version = "0.3.12"
407407source = "registry+https://github.com/rust-lang/crates.io-index"
408−checksum = "f01c61843314e95f96cc9245702248733a3a3d744e43e2e755e3c7af8348a0a9"
408+checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846"
409409dependencies = [
410410 "futures-core",
411411 "futures-sink",
@@ -413,15 +413,15 @@ dependencies = [
413413
414414[[package]]
415415name = "futures-core"
416−version = "0.3.9"
416+version = "0.3.12"
417417source = "registry+https://github.com/rust-lang/crates.io-index"
418−checksum = "db8d3b0917ff63a2a96173133c02818fac4a746b0a57569d3baca9ec0e945e08"
418+checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65"
419419
420420[[package]]
421421name = "futures-executor"
422−version = "0.3.9"
422+version = "0.3.12"
423423source = "registry+https://github.com/rust-lang/crates.io-index"
424−checksum = "9ee9ca2f7eb4475772cf39dd1cd06208dce2670ad38f4d9c7262b3e15f127068"
424+checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9"
425425dependencies = [
426426 "futures-core",
427427 "futures-task",
@@ -430,9 +430,9 @@ dependencies = [
430430
431431[[package]]
432432name = "futures-io"
433−version = "0.3.9"
433+version = "0.3.12"
434434source = "registry+https://github.com/rust-lang/crates.io-index"
435−checksum = "e37c1a51b037b80922864b8eed90692c5cd8abd4c71ce49b77146caa47f3253b"
435+checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500"
436436
437437[[package]]
438438name = "futures-lite"
@@ -445,15 +445,15 @@ dependencies = [
445445 "futures-io",
446446 "memchr",
447447 "parking",
448− "pin-project-lite 0.2.1",
448+ "pin-project-lite 0.2.4",
449449 "waker-fn",
450450]
451451
452452[[package]]
453453name = "futures-macro"
454−version = "0.3.9"
454+version = "0.3.12"
455455source = "registry+https://github.com/rust-lang/crates.io-index"
456−checksum = "0f8719ca0e1f3c5e34f3efe4570ef2c0610ca6da85ae7990d472e9cbfba13664"
456+checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd"
457457dependencies = [
458458 "proc-macro-hack",
459459 "proc-macro2",
@@ -463,24 +463,24 @@ dependencies = [
463463
464464[[package]]
465465name = "futures-sink"
466−version = "0.3.9"
466+version = "0.3.12"
467467source = "registry+https://github.com/rust-lang/crates.io-index"
468−checksum = "f6adabac1290109cfa089f79192fb6244ad2c3f1cc2281f3e1dd987592b71feb"
468+checksum = "caf5c69029bda2e743fddd0582d1083951d65cc9539aebf8812f36c3491342d6"
469469
470470[[package]]
471471name = "futures-task"
472−version = "0.3.9"
472+version = "0.3.12"
473473source = "registry+https://github.com/rust-lang/crates.io-index"
474−checksum = "a92a0843a2ff66823a8f7c77bffe9a09be2b64e533562c412d63075643ec0038"
474+checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86"
475475dependencies = [
476476 "once_cell",
477477]
478478
479479[[package]]
480480name = "futures-util"
481−version = "0.3.9"
481+version = "0.3.12"
482482source = "registry+https://github.com/rust-lang/crates.io-index"
483−checksum = "036a2107cdeb57f6d7322f1b6c363dad67cd63ca3b7d1b925bdf75bd5d96cda9"
483+checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b"
484484dependencies = [
485485 "futures-channel",
486486 "futures-core",
@@ -489,7 +489,7 @@ dependencies = [
489489 "futures-sink",
490490 "futures-task",
491491 "memchr",
492− "pin-project-lite 0.2.1",
492+ "pin-project-lite 0.2.4",
493493 "pin-utils",
494494 "proc-macro-hack",
495495 "proc-macro-nested",
@@ -507,13 +507,13 @@ dependencies = [
507507
508508[[package]]
509509name = "getrandom"
510−version = "0.1.16"
510+version = "0.2.2"
511511source = "registry+https://github.com/rust-lang/crates.io-index"
512−checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
512+checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
513513dependencies = [
514514 "cfg-if 1.0.0",
515515 "libc",
516− "wasi 0.9.0+wasi-snapshot-preview1",
516+ "wasi",
517517]
518518
519519[[package]]
@@ -621,6 +621,7 @@ dependencies = [
621621 "helix-core",
622622 "helix-lsp",
623623 "once_cell",
624+ "slotmap",
624625 "smol",
625626 "tui",
626627 "url",
@@ -628,9 +629,9 @@ dependencies = [
628629
629630[[package]]
630631name = "hermit-abi"
631−version = "0.1.17"
632+version = "0.1.18"
632633source = "registry+https://github.com/rust-lang/crates.io-index"
633−checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
634+checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
634635dependencies = [
635636 "libc",
636637]
@@ -719,9 +720,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
719720
720721[[package]]
721722name = "libc"
722−version = "0.2.82"
723+version = "0.2.85"
723724source = "registry+https://github.com/rust-lang/crates.io-index"
724−checksum = "89203f3fba0a3795506acaad8ebce3c80c0af93f994d5a1d7a0b1eeb23271929"
725+checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3"
725726
726727[[package]]
727728name = "lock_api"
@@ -734,11 +735,11 @@ dependencies = [
734735
735736[[package]]
736737name = "log"
737−version = "0.4.11"
738+version = "0.4.14"
738739source = "registry+https://github.com/rust-lang/crates.io-index"
739−checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
740+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
740741dependencies = [
741− "cfg-if 0.1.10",
742+ "cfg-if 1.0.0",
742743]
743744
744745[[package]]
@@ -897,7 +898,7 @@ dependencies = [
897898 "cfg-if 1.0.0",
898899 "instant",
899900 "libc",
900− "redox_syscall",
901+ "redox_syscall 0.1.57",
901902 "smallvec",
902903 "winapi",
903904]
@@ -922,9 +923,9 @@ checksum = "c917123afa01924fc84bb20c4c03f004d9c38e5127e3c039bbf7f4b9c76a2f6b"
922923
923924[[package]]
924925name = "pin-project-lite"
925−version = "0.2.1"
926+version = "0.2.4"
926927source = "registry+https://github.com/rust-lang/crates.io-index"
927−checksum = "e36743d754ccdf9954c2e352ce2d4b106e024c814f6499c2dadff80da9a442d8"
928+checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
928929
929930[[package]]
930931name = "pin-utils"
@@ -953,9 +954,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
953954
954955[[package]]
955956name = "proc-macro-nested"
956−version = "0.1.6"
957+version = "0.1.7"
957958source = "registry+https://github.com/rust-lang/crates.io-index"
958−checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
959+checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
959960
960961[[package]]
961962name = "proc-macro2"
@@ -1006,21 +1007,30 @@ version = "0.1.57"
10061007source = "registry+https://github.com/rust-lang/crates.io-index"
10071008checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce"
10081009
1010+[[package]]
1011+name = "redox_syscall"
1012+version = "0.2.4"
1013+source = "registry+https://github.com/rust-lang/crates.io-index"
1014+checksum = "05ec8ca9416c5ea37062b502703cd7fcb207736bc294f6e0cf367ac6fc234570"
1015+dependencies = [
1016+ "bitflags",
1017+]
1018+
10091019[[package]]
10101020name = "redox_users"
1011−version = "0.3.5"
1021+version = "0.4.0"
10121022source = "registry+https://github.com/rust-lang/crates.io-index"
1013−checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d"
1023+checksum = "528532f3d801c87aec9def2add9ca802fe569e44a544afe633765267840abe64"
10141024dependencies = [
10151025 "getrandom",
1016− "redox_syscall",
1026+ "redox_syscall 0.2.4",
10171027]
10181028
10191029[[package]]
10201030name = "regex"
1021−version = "1.4.2"
1031+version = "1.4.3"
10221032source = "registry+https://github.com/rust-lang/crates.io-index"
1023−checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
1033+checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a"
10241034dependencies = [
10251035 "aho-corasick",
10261036 "memchr",
@@ -1030,9 +1040,9 @@ dependencies = [
10301040
10311041[[package]]
10321042name = "regex-syntax"
1033−version = "0.6.21"
1043+version = "0.6.22"
10341044source = "registry+https://github.com/rust-lang/crates.io-index"
1035−checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
1045+checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581"
10361046
10371047[[package]]
10381048name = "ropey"
@@ -1066,18 +1076,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
10661076
10671077[[package]]
10681078name = "serde"
1069−version = "1.0.118"
1079+version = "1.0.123"
10701080source = "registry+https://github.com/rust-lang/crates.io-index"
1071−checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
1081+checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae"
10721082dependencies = [
10731083 "serde_derive",
10741084]
10751085
10761086[[package]]
10771087name = "serde_derive"
1078−version = "1.0.118"
1088+version = "1.0.123"
10791089source = "registry+https://github.com/rust-lang/crates.io-index"
1080−checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
1090+checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31"
10811091dependencies = [
10821092 "proc-macro2",
10831093 "quote",
@@ -1141,11 +1151,20 @@ version = "0.4.2"
11411151source = "registry+https://github.com/rust-lang/crates.io-index"
11421152checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8"
11431153
1154+[[package]]
1155+name = "slotmap"
1156+version = "1.0.2"
1157+source = "registry+https://github.com/rust-lang/crates.io-index"
1158+checksum = "ab3003725ae562cf995f3dc82bb99e70926e09000396816765bb6d7adbe740b1"
1159+dependencies = [
1160+ "version_check",
1161+]
1162+
11441163[[package]]
11451164name = "smallvec"
1146−version = "1.6.0"
1165+version = "1.6.1"
11471166source = "registry+https://github.com/rust-lang/crates.io-index"
1148−checksum = "1a55ca5f3b68e41c979bf8c46a6f1da892ca4db8f94023ce0bd32407573b1ac0"
1167+checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e"
11491168
11501169[[package]]
11511170name = "smol"
@@ -1188,9 +1207,9 @@ dependencies = [
11881207
11891208[[package]]
11901209name = "syn"
1191−version = "1.0.58"
1210+version = "1.0.60"
11921211source = "registry+https://github.com/rust-lang/crates.io-index"
1193−checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5"
1212+checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081"
11941213dependencies = [
11951214 "proc-macro2",
11961215 "quote",
@@ -1199,8 +1218,8 @@ dependencies = [
11991218
12001219[[package]]
12011220name = "tendril"
1202−version = "0.4.1"
1203−source = "git+https://github.com/servo/tendril#9532724c32a0bf5e65acb56209373d97223bc530"
1221+version = "0.4.2"
1222+source = "git+https://github.com/servo/tendril#548cfaab79a3db13f350621d5b18a81d351463ba"
12041223dependencies = [
12051224 "futf",
12061225 "mac",
@@ -1238,29 +1257,28 @@ dependencies = [
12381257
12391258[[package]]
12401259name = "thread_local"
1241−version = "1.1.0"
1260+version = "1.1.2"
12421261source = "registry+https://github.com/rust-lang/crates.io-index"
1243−checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447"
1262+checksum = "d8208a331e1cb318dd5bd76951d2b8fc48ca38a69f5f4e4af1b6a9f8c6236915"
12441263dependencies = [
1245− "lazy_static",
1264+ "once_cell",
12461265]
12471266
12481267[[package]]
12491268name = "time"
1250−version = "0.1.44"
1269+version = "0.1.43"
12511270source = "registry+https://github.com/rust-lang/crates.io-index"
1252−checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
1271+checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
12531272dependencies = [
12541273 "libc",
1255− "wasi 0.10.0+wasi-snapshot-preview1",
12561274 "winapi",
12571275]
12581276
12591277[[package]]
12601278name = "tinyvec"
1261−version = "1.1.0"
1279+version = "1.1.1"
12621280source = "registry+https://github.com/rust-lang/crates.io-index"
1263−checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f"
1281+checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023"
12641282dependencies = [
12651283 "tinyvec_macros",
12661284]
@@ -1360,6 +1378,12 @@ version = "0.8.2"
13601378source = "registry+https://github.com/rust-lang/crates.io-index"
13611379checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
13621380
1381+[[package]]
1382+name = "version_check"
1383+version = "0.9.2"
1384+source = "registry+https://github.com/rust-lang/crates.io-index"
1385+checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
1386+
13631387[[package]]
13641388name = "waker-fn"
13651389version = "1.1.0"
@@ -1379,15 +1403,9 @@ dependencies = [
13791403
13801404[[package]]
13811405name = "wasi"
1382−version = "0.9.0+wasi-snapshot-preview1"
1383−source = "registry+https://github.com/rust-lang/crates.io-index"
1384−checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
1385−
1386−[[package]]
1387−name = "wasi"
1388−version = "0.10.0+wasi-snapshot-preview1"
1406+version = "0.10.2+wasi-snapshot-preview1"
13891407source = "registry+https://github.com/rust-lang/crates.io-index"
1390−checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
1408+checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
13911409
13921410[[package]]
13931411name = "wepoll-sys"
helix-term/src/application.rs+11−8
@@ -39,11 +39,12 @@ impl Application {
3939 pub fn new(mut args: Args, executor: &'static smol::Executor<'static>) -> Result<Self, Error> {
4040 let backend = CrosstermBackend::new(stdout());
4141 let mut terminal = Terminal::new(backend)?;
42− let mut editor = Editor::new();
4342 let size = terminal.size()?;
43+ let mut editor = Editor::new(size);
4444
45− if let Some(file) = args.values_of_t::<PathBuf>("files").unwrap().pop() {
46− editor.open(file, (size.width, size.height), executor)?;
45+ let files = args.values_of_t::<PathBuf>("files").unwrap();
46+ for file in files {
47+ editor.open(file, executor)?;
4748 }
4849
4950 let mut compositor = Compositor::new();
@@ -132,11 +133,13 @@ impl Application {
132133 Notification::PublishDiagnostics(params) => {
133134 let path = Some(params.uri.to_file_path().unwrap());
134135
135− let view = self
136− .editor
137− .views
138− .iter_mut()
139− .find(|view| view.doc.path == path);
136+ let view: Option<&mut View> = None;
137+ // TODO
138+ // let view = self
139+ // .editor
140+ // .views
141+ // .iter_mut()
142+ // .find(|view| view.doc.path == path);
140143
141144 if let Some(view) = view {
142145 let doc = view.doc.text().slice(..);
helix-term/src/commands.rs+54−57
@@ -183,7 +183,7 @@ pub fn check_cursor_in_view(view: &View) -> bool {
183183 let doc = &view.doc;
184184 let cursor = doc.selection().cursor();
185185 let line = doc.text().char_to_line(cursor);
186− let document_end = view.first_line + view.size.1.saturating_sub(1) as usize;
186+ let document_end = view.first_line + view.area.height.saturating_sub(1) as usize;
187187
188188 if (line > document_end.saturating_sub(PADDING)) | (line < view.first_line + PADDING) {
189189 return false;
@@ -197,7 +197,7 @@ pub fn page_up(cx: &mut Context) {
197197 return;
198198 }
199199
200− view.first_line = view.first_line.saturating_sub(view.size.1 as usize);
200+ view.first_line = view.first_line.saturating_sub(view.area.height as usize);
201201
202202 if !check_cursor_in_view(view) {
203203 let text = view.doc.text();
@@ -208,7 +208,7 @@ pub fn page_up(cx: &mut Context) {
208208
209209pub fn page_down(cx: &mut Context) {
210210 let view = cx.view();
211− view.first_line += view.size.1 as usize + PADDING;
211+ view.first_line += view.area.height as usize + PADDING;
212212
213213 if view.first_line < view.doc.text().len_lines() {
214214 let text = view.doc.text();
@@ -223,7 +223,9 @@ pub fn half_page_up(cx: &mut Context) {
223223 return;
224224 }
225225
226− view.first_line = view.first_line.saturating_sub(view.size.1 as usize / 2);
226+ view.first_line = view
227+ .first_line
228+ .saturating_sub(view.area.height as usize / 2);
227229
228230 if !check_cursor_in_view(view) {
229231 let text = &view.doc.text();
@@ -235,8 +237,8 @@ pub fn half_page_up(cx: &mut Context) {
235237pub fn half_page_down(cx: &mut Context) {
236238 let view = cx.view();
237239 let lines = view.doc.text().len_lines();
238− if view.first_line < lines.saturating_sub(view.size.1 as usize) {
239− view.first_line += view.size.1 as usize / 2;
240+ if view.first_line < lines.saturating_sub(view.area.height as usize) {
241+ view.first_line += view.area.height as usize / 2;
240242 }
241243 if !check_cursor_in_view(view) {
242244 let text = view.doc.text();
@@ -367,8 +369,7 @@ pub fn change_selection(cx: &mut Context) {
367369
368370pub fn collapse_selection(cx: &mut Context) {
369371 let selection = cx
370− .view()
371− .doc
372+ .doc()
372373 .selection()
373374 .transform(|range| Range::new(range.head, range.head));
374375
@@ -377,8 +378,7 @@ pub fn collapse_selection(cx: &mut Context) {
377378
378379pub fn flip_selections(cx: &mut Context) {
379380 let selection = cx
380− .view()
381− .doc
381+ .doc()
382382 .selection()
383383 .transform(|range| Range::new(range.head, range.anchor));
384384
@@ -396,8 +396,7 @@ pub fn insert_mode(cx: &mut Context) {
396396 enter_insert_mode(cx);
397397
398398 let selection = cx
399− .view()
400− .doc
399+ .doc()
401400 .selection()
402401 .transform(|range| Range::new(range.to(), range.from()));
403402 cx.doc().set_selection(selection);
@@ -431,37 +430,40 @@ pub fn command_mode(cx: &mut Context) {
431430 |_input: &str| {
432431 // TODO: i need this duplicate list right now to avoid borrow checker issues
433432 let command_list = vec![
434− String::from("q"),
435− String::from("aaa"),
436− String::from("bbb"),
437− String::from("ccc"),
438− String::from("ddd"),
439− String::from("eee"),
440− String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
441− String::from("q"),
442− String::from("aaa"),
443− String::from("bbb"),
444− String::from("ccc"),
445− String::from("ddd"),
446− String::from("eee"),
447− String::from("q"),
448− String::from("aaa"),
449− String::from("bbb"),
450− String::from("ccc"),
451− String::from("ddd"),
452− String::from("eee"),
453− String::from("q"),
454− String::from("aaa"),
455− String::from("bbb"),
456− String::from("ccc"),
457− String::from("ddd"),
458− String::from("eee"),
459− String::from("q"),
460− String::from("aaa"),
461− String::from("bbb"),
462− String::from("ccc"),
463− String::from("ddd"),
464− String::from("eee"),
433+ "q".to_string(),
434+ "o".to_string(),
435+ "w".to_string(),
436+ // String::from("q"),
437+ // String::from("aaa"),
438+ // String::from("bbb"),
439+ // String::from("ccc"),
440+ // String::from("ddd"),
441+ // String::from("eee"),
442+ // String::from("averylongcommandaverylongcommandaverylongcommandaverylongcommandaverylongcommand"),
443+ // String::from("q"),
444+ // String::from("aaa"),
445+ // String::from("bbb"),
446+ // String::from("ccc"),
447+ // String::from("ddd"),
448+ // String::from("eee"),
449+ // String::from("q"),
450+ // String::from("aaa"),
451+ // String::from("bbb"),
452+ // String::from("ccc"),
453+ // String::from("ddd"),
454+ // String::from("eee"),
455+ // String::from("q"),
456+ // String::from("aaa"),
457+ // String::from("bbb"),
458+ // String::from("ccc"),
459+ // String::from("ddd"),
460+ // String::from("eee"),
461+ // String::from("q"),
462+ // String::from("aaa"),
463+ // String::from("bbb"),
464+ // String::from("ccc"),
465+ // String::from("ddd"),
466+ // String::from("eee"),
465467 ];
466468 command_list
467469 .into_iter()
@@ -478,8 +480,7 @@ pub fn command_mode(cx: &mut Context) {
478480 match *parts.as_slice() {
479481 ["q"] => editor.should_close = true,
480482 ["o", path] => {
481− let size = editor.view().size;
482− editor.open(path.into(), size, executor);
483+ editor.open(path.into(), executor);
483484 }
484485 _ => (),
485486 }
@@ -499,12 +500,13 @@ pub fn file_picker(cx: &mut Context) {
499500}
500501
501502pub fn buffer_picker(cx: &mut Context) {
502− cx.callback = Some(Box::new(
503− |compositor: &mut Compositor, editor: &mut Editor| {
504− let picker = ui::buffer_picker(&editor.views, editor.focus);
505− compositor.push(Box::new(picker));
506− },
507− ));
503+ unimplemented!()
504+ // cx.callback = Some(Box::new(
505+ // |compositor: &mut Compositor, editor: &mut Editor| {
506+ // let picker = ui::buffer_picker(&editor.views, editor.focus);
507+ // compositor.push(Box::new(picker));
508+ // },
509+ // ));
508510}
509511
510512// calculate line numbers for each selection range
@@ -617,12 +619,7 @@ fn append_changes_to_history(cx: &mut Context) {
617619 // TODO: trigger lsp/documentDidChange with changes
618620
619621 // HAXX: we need to reconstruct the state as it was before the changes..
620− let old_state = cx
621− .view()
622− .doc
623− .old_state
624− .take()
625− .expect("no old_state available");
622+ let old_state = cx.doc().old_state.take().expect("no old_state available");
626623
627624 // TODO: take transaction by value?
628625 cx.doc().history.commit_revision(&transaction, &old_state);
helix-term/src/ui/editor.rs+34−16
@@ -37,15 +37,20 @@ impl EditorView {
3737 surface: &mut Surface,
3838 theme: &Theme,
3939 ) {
40− let area = Rect::new(OFFSET, 0, viewport.width - OFFSET, viewport.height - 2); // - 2 for statusline and prompt
40+ let area = Rect::new(
41+ viewport.x + OFFSET,
42+ viewport.y,
43+ viewport.width - OFFSET,
44+ viewport.height - 2,
45+ ); // - 2 for statusline and prompt
4146 self.render_buffer(view, area, surface, theme);
4247
4348 // clear with background color
4449 // TODO: this seems to prevent setting style later
4550 // surface.set_style(viewport, theme.get("ui.background"));
4651
47− let area = Rect::new(0, viewport.height - 2, viewport.width, 1);
48− self.render_statusline(view, area, surface, theme);
52+ let area = Rect::new(viewport.x, viewport.height - 2, viewport.width, 1);
53+ self.render_statusline(&view.doc, area, surface, theme);
4954 }
5055
5156 // TODO: ideally not &mut View but highlights require it because of cursor cache
@@ -203,34 +208,46 @@ impl EditorView {
203208 let last_line = view.last_line();
204209 for (i, line) in (view.first_line..last_line).enumerate() {
205210 if view.doc.diagnostics.iter().any(|d| d.line == line) {
206− surface.set_stringn(0, i as u16, "●", 1, warning);
211+ surface.set_stringn(
212+ viewport.x + 0 - OFFSET,
213+ viewport.y + i as u16,
214+ "●",
215+ 1,
216+ warning,
217+ );
207218 }
208219
209− surface.set_stringn(1, i as u16, format!("{:>5}", line + 1), 5, style);
220+ surface.set_stringn(
221+ viewport.x + 1 - OFFSET,
222+ viewport.y + i as u16,
223+ format!("{:>5}", line + 1),
224+ 5,
225+ style,
226+ );
210227 }
211228 }
212229
213230 pub fn render_statusline(
214231 &self,
215− view: &View,
232+ doc: &Document,
216233 viewport: Rect,
217234 surface: &mut Surface,
218235 theme: &Theme,
219236 ) {
220237 let text_color = text_color();
221− let mode = match view.doc.mode() {
238+ let mode = match doc.mode() {
222239 Mode::Insert => "INS",
223240 Mode::Normal => "NOR",
224241 Mode::Goto => "GOTO",
225242 };
226243 // statusline
227244 surface.set_style(
228− Rect::new(0, viewport.y, viewport.width, 1),
245+ Rect::new(viewport.x, viewport.y, viewport.width, 1),
229246 theme.get("ui.statusline"),
230247 );
231− surface.set_string(1, viewport.y, mode, text_color);
248+ surface.set_string(viewport.x + 1, viewport.y, mode, text_color);
232249
233− if let Some(path) = view.doc.relative_path() {
250+ if let Some(path) = doc.relative_path() {
234251 let path = path.to_string_lossy();
235252 surface.set_string(6, viewport.y, path, text_color);
236253 // TODO: append [+] if modified
@@ -239,7 +256,7 @@ impl EditorView {
239256 surface.set_string(
240257 viewport.width - 10,
241258 viewport.y,
242− format!("{}", view.doc.diagnostics.len()),
259+ format!("{}", doc.diagnostics.len()),
243260 text_color,
244261 );
245262 }
@@ -251,9 +268,8 @@ impl Component for EditorView {
251268 Event::Resize(width, height) => {
252269 // TODO: simplistic ensure cursor in view for now
253270 // TODO: loop over views
254− let view = cx.editor.view_mut();
255− view.size = (width, height);
256− view.ensure_cursor_in_view();
271+ cx.editor.tree.resize(Rect::new(0, 0, width, height));
272+ // TODO: restore view.ensure_cursor_in_view();
257273 EventResult::Consumed(None)
258274 }
259275 Event::Key(event) => {
@@ -306,8 +322,10 @@ impl Component for EditorView {
306322 // SAFETY: we cheat around the view_mut() borrow because it doesn't allow us to also borrow
307323 // theme. Theme is immutable mutating view won't disrupt theme_ref.
308324 let theme_ref = unsafe { &*(&cx.editor.theme as *const Theme) };
309− let view = cx.editor.view_mut();
310− self.render_view(view, area, surface, theme_ref);
325+ for view in cx.editor.tree.views() {
326+ // TODO: use parent area
327+ self.render_view(view, view.area, surface, theme_ref);
328+ }
311329
312330 // TODO: drop unwrap
313331 }
helix-term/src/ui/mod.rs+28−28
@@ -82,38 +82,38 @@ pub fn file_picker(root: &str, ex: &'static smol::Executor) -> Picker<PathBuf> {
8282 path.strip_prefix("./").unwrap().to_str().unwrap().into()
8383 },
8484 move |editor: &mut Editor, path: &PathBuf| {
85− let size = editor.view().size;
86− editor.open(path.into(), size, ex);
85+ editor.open(path.into(), ex);
8786 },
8887 )
8988}
9089
9190use helix_view::View;
9291pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>, usize)> {
93− use helix_view::Editor;
94− Picker::new(
95− views
96− .iter()
97− .enumerate()
98− .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
99− .collect(),
100− move |(path, index): &(Option<PathBuf>, usize)| {
101− // format_fn
102− match path {
103− Some(path) => {
104− if *index == current {
105− format!("{} (*)", path.to_str().unwrap()).into()
106− } else {
107− path.to_str().unwrap().into()
108− }
109− }
110− None => "[NEW]".into(),
111− }
112− },
113− |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
114− if index < editor.views.len() {
115− editor.focus = index;
116− }
117− },
118− )
92+ unimplemented!();
93+ // use helix_view::Editor;
94+ // Picker::new(
95+ // views
96+ // .iter()
97+ // .enumerate()
98+ // .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
99+ // .collect(),
100+ // move |(path, index): &(Option<PathBuf>, usize)| {
101+ // // format_fn
102+ // match path {
103+ // Some(path) => {
104+ // if *index == current {
105+ // format!("{} (*)", path.to_str().unwrap()).into()
106+ // } else {
107+ // path.to_str().unwrap().into()
108+ // }
109+ // }
110+ // None => "[NEW]".into(),
111+ // }
112+ // },
113+ // |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
114+ // if index < editor.views.len() {
115+ // editor.focus = index;
116+ // }
117+ // },
118+ // )
119119}
helix-view/Cargo.toml+2
@@ -24,3 +24,5 @@ url = "2"
2424
2525smol = "1"
2626futures-util = "0.3"
27+
28+slotmap = "1"
helix-view/src/editor.rs+13−21
@@ -1,45 +1,36 @@
11use crate::theme::Theme;
2+use crate::tree::Tree;
23use crate::{Document, View};
4+use slotmap::DefaultKey as Key;
35
46use std::path::PathBuf;
57
68use anyhow::Error;
79
810pub struct Editor {
9− pub views: Vec<View>,
10− pub focus: usize,
11+ pub tree: Tree,
12+ // pub documents: Vec<Document>,
13+ pub focus: Key,
1114 pub should_close: bool,
1215 pub theme: Theme, // TODO: share one instance
1316 pub language_servers: helix_lsp::Registry,
1417}
1518
16−impl Default for Editor {
17− fn default() -> Self {
18− Self::new()
19− }
20−}
21−
2219impl Editor {
23− pub fn new() -> Self {
20+ pub fn new(area: tui::layout::Rect) -> Self {
2421 let theme = Theme::default();
2522 let language_servers = helix_lsp::Registry::new();
2623
2724 Self {
28− views: Vec::new(),
29− focus: 0,
25+ tree: Tree::new(area),
26+ focus: Key::default(),
3027 should_close: false,
3128 theme,
3229 language_servers,
3330 }
3431 }
3532
36− pub fn open(
37− &mut self,
38− path: PathBuf,
39− size: (u16, u16),
40− executor: &smol::Executor,
41− ) -> Result<(), Error> {
42− let pos = self.views.len();
33+ pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
4334 let mut doc = Document::load(path, self.theme.scopes())?;
4435
4536 // try to find a language server based on the language name
@@ -60,16 +51,17 @@ impl Editor {
6051 .unwrap();
6152 }
6253
63− self.views.push(View::new(doc, size)?);
54+ let view = View::new(doc)?;
55+ let pos = self.tree.insert(view);
6456 self.focus = pos;
6557 Ok(())
6658 }
6759
6860 pub fn view(&self) -> &View {
69− self.views.get(self.focus).unwrap()
61+ self.tree.get(self.focus)
7062 }
7163
7264 pub fn view_mut(&mut self) -> &mut View {
73− self.views.get_mut(self.focus).unwrap()
65+ self.tree.get_mut(self.focus)
7466 }
7567}
helix-view/src/lib.rs+1
@@ -1,6 +1,7 @@
11pub mod document;
22pub mod editor;
33pub mod theme;
4+pub mod tree;
45pub mod view;
56
67pub use document::Document;
helix-view/src/view.rs+5−5
@@ -17,15 +17,15 @@ pub const PADDING: usize = 5;
1717pub struct View {
1818 pub doc: Document,
1919 pub first_line: usize,
20− pub size: (u16, u16),
20+ pub area: Rect,
2121}
2222
2323impl View {
24− pub fn new(doc: Document, size: (u16, u16)) -> Result<Self, Error> {
24+ pub fn new(doc: Document) -> Result<Self, Error> {
2525 let view = Self {
2626 doc,
2727 first_line: 0,
28− size,
28+ area: Rect::default(), // will get calculated upon inserting into tree
2929 };
3030
3131 Ok(view)
@@ -34,7 +34,7 @@ impl View {
3434 pub fn ensure_cursor_in_view(&mut self) {
3535 let cursor = self.doc.state.selection().cursor();
3636 let line = self.doc.text().char_to_line(cursor);
37− let document_end = self.first_line + (self.size.1 as usize).saturating_sub(2);
37+ let document_end = self.first_line + (self.area.height as usize).saturating_sub(2);
3838
3939 // TODO: side scroll
4040
@@ -50,7 +50,7 @@ impl View {
5050 /// Calculates the last visible line on screen
5151 #[inline]
5252 pub fn last_line(&self) -> usize {
53− let viewport = Rect::new(6, 0, self.size.0, self.size.1 - 2); // - 2 for statusline and prompt
53+ let viewport = Rect::new(6, 0, self.area.width, self.area.height - 2); // - 2 for statusline and prompt
5454 std::cmp::min(
5555 self.first_line + (viewport.height as usize),
5656 self.doc.text().len_lines() - 1,