From ce97a2f05fcddf81d8210ec6b25411f8fd7d867a Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sat, 19 Jun 2021 13:26:52 +0200 Subject: Add ability to change theme on editor --- helix-term/src/ui/completion.rs | 43 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) (limited to 'helix-term/src/ui/completion.rs') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 06ed966d..88a71534 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -246,34 +246,43 @@ impl Component for Completion { value: contents, })) => { // TODO: convert to wrapped text - Markdown::new(format!( - "```{}\n{}\n```\n{}", - language, - option.detail.as_deref().unwrap_or_default(), - contents.clone() - )) + Markdown::new( + format!( + "```{}\n{}\n```\n{}", + language, + option.detail.as_deref().unwrap_or_default(), + contents.clone() + ), + cx.editor.syn_loader.clone(), + ) } Some(lsp::Documentation::MarkupContent(lsp::MarkupContent { kind: lsp::MarkupKind::Markdown, value: contents, })) => { // TODO: set language based on doc scope - Markdown::new(format!( - "```{}\n{}\n```\n{}", - language, - option.detail.as_deref().unwrap_or_default(), - contents.clone() - )) + Markdown::new( + format!( + "```{}\n{}\n```\n{}", + language, + option.detail.as_deref().unwrap_or_default(), + contents.clone() + ), + cx.editor.syn_loader.clone(), + ) } None if option.detail.is_some() => { // TODO: copied from above // TODO: set language based on doc scope - Markdown::new(format!( - "```{}\n{}\n```", - language, - option.detail.as_deref().unwrap_or_default(), - )) + Markdown::new( + format!( + "```{}\n{}\n```", + language, + option.detail.as_deref().unwrap_or_default(), + ), + cx.editor.syn_loader.clone(), + ) } None => return, }; -- cgit v1.2.3-70-g09d2 From 980e6023523119676652b49692eb5f844d84d703 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sun, 20 Jun 2021 06:13:44 +0200 Subject: Make completion window move to top when cursor is below half --- helix-term/src/ui/completion.rs | 13 +++++++++++-- helix-term/src/ui/markdown.rs | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'helix-term/src/ui/completion.rs') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 88a71534..f4d882de 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -238,6 +238,9 @@ impl Component for Completion { .language() .and_then(|scope| scope.strip_prefix("source.")) .unwrap_or(""); + let cursor_pos = doc.selection(view.id).cursor(); + let cursor_pos = + helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row - view.first_line; let doc = match &option.documentation { Some(lsp::Documentation::String(contents)) @@ -289,8 +292,14 @@ impl Component for Completion { let half = area.height / 2; let height = 15.min(half); - // -2 to subtract command line + statusline. a bit of a hack, because of splits. - let area = Rect::new(0, area.height - height - 2, area.width, height); + let y = if cursor_pos > half as usize { + 0 + } else { + // -2 to subtract command line + statusline. a bit of a hack, because of splits. + area.height.saturating_sub(height).saturating_sub(2) + }; + + let area = Rect::new(0, y, area.width, height); // clear area let background = cx.editor.theme.get("ui.popup"); diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 91086f7b..75e2f4b4 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -162,7 +162,6 @@ fn parse<'a>( } } Event::Code(text) | Event::Html(text) => { - log::warn!("code {:?}", text); let mut span = to_span(text); span.style = code_style; spans.push(span); -- cgit v1.2.3-70-g09d2 From 0882712b4598586ce7c9b8e8f446d6a6fc5ff060 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sun, 20 Jun 2021 07:15:08 +0200 Subject: Use full screen size --- helix-term/src/ui/completion.rs | 8 +++++--- helix-view/src/tree.rs | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'helix-term/src/ui/completion.rs') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index f4d882de..256d8f7d 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -239,8 +239,8 @@ impl Component for Completion { .and_then(|scope| scope.strip_prefix("source.")) .unwrap_or(""); let cursor_pos = doc.selection(view.id).cursor(); - let cursor_pos = - helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row - view.first_line; + let cursor_pos = (helix_core::coords_at_pos(doc.text().slice(..), cursor_pos).row + - view.first_line) as u16; let doc = match &option.documentation { Some(lsp::Documentation::String(contents)) @@ -292,7 +292,9 @@ impl Component for Completion { let half = area.height / 2; let height = 15.min(half); - let y = if cursor_pos > half as usize { + let y = if cursor_pos + view.area.y + >= (cx.editor.tree.area().height - height - 1/* statusline */) + { 0 } else { // -2 to subtract command line + statusline. a bit of a hack, because of splits. diff --git a/helix-view/src/tree.rs b/helix-view/src/tree.rs index a0c466d9..f7d6c1f2 100644 --- a/helix-view/src/tree.rs +++ b/helix-view/src/tree.rs @@ -434,6 +434,10 @@ impl Tree { self.focus = key; } } + + pub fn area(&self) -> Rect { + self.area + } } #[derive(Debug)] -- cgit v1.2.3-70-g09d2 From fc39a6c40df7d4a28994db762554815c37470073 Mon Sep 17 00:00:00 2001 From: wojciechkepka Date: Sun, 20 Jun 2021 12:35:12 +0200 Subject: Add comment, statusline + commandline = 2 --- helix-term/src/ui/completion.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'helix-term/src/ui/completion.rs') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 256d8f7d..80f7d590 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -292,8 +292,9 @@ impl Component for Completion { let half = area.height / 2; let height = 15.min(half); + // we want to make sure the cursor is visible (not hidden behind the documentation) let y = if cursor_pos + view.area.y - >= (cx.editor.tree.area().height - height - 1/* statusline */) + >= (cx.editor.tree.area().height - height - 2/* statusline + commandline */) { 0 } else { -- cgit v1.2.3-70-g09d2