@@ -1,7 +1,9 @@
1use crate::compositor::{Component, Compositor, Context, Event, EventResult};
1use crate::compositor::{Component, Compositor, Context, Event, EventResult};
2use crate::{alt, ctrl, key, shift, ui};
2use crate::{alt, ctrl, key, shift, ui};
3+use helix_core::syntax;
3use helix_view::input::KeyEvent;
4use helix_view::input::KeyEvent;
4use helix_view::keyboard::KeyCode;
5use helix_view::keyboard::KeyCode;
5use std::{borrow::Cow, ops::RangeFrom};
7use std::{borrow::Cow, ops::RangeFrom};
6use tui::buffer::Buffer as Surface;
8use tui::buffer::Buffer as Surface;
7use tui::widgets::{Block, Borders, Widget};
9use tui::widgets::{Block, Borders, Widget};
@@ -32,6 +34,7 @@ pub struct Prompt {
32 callback_fn: CallbackFn,
34 callback_fn: CallbackFn,
33 pub doc_fn: DocFn,
35 pub doc_fn: DocFn,
34 next_char_handler: Option<PromptCharHandler>,
36 next_char_handler: Option<PromptCharHandler>,
37+ language: Option<(&'static str, Arc<syntax::Loader>)>,
37#[derive(Clone, Copy, PartialEq, Eq)]
40#[derive(Clone, Copy, PartialEq, Eq)]
@@ -83,6 +86,7 @@ impl Prompt {
83 callback_fn: Box::new(callback_fn),
86 callback_fn: Box::new(callback_fn),
84 doc_fn: Box::new(|_| None),
87 doc_fn: Box::new(|_| None),
85 next_char_handler: None,
88 next_char_handler: None,
@@ -94,6 +98,11 @@ impl Prompt {
101+ pub fn with_language(mut self, language: &'static str, loader: Arc<syntax::Loader>) -> Self {
102+ self.language = Some((language, loader));
97 pub fn line(&self) -> &String {
106 pub fn line(&self) -> &String {
98 &self.line
107 &self.line
@@ -456,30 +465,28 @@ impl Prompt {
456 // render buffer text
465 // render buffer text
457 surface.set_string(area.x, area.y + line, &self.prompt, prompt_color);
466 surface.set_string(area.x, area.y + line, &self.prompt, prompt_color);
468+ let line_area = area.clip_left(self.prompt.len() as u16).clip_top(line);
459− let (input, is_suggestion): (Cow<str>, bool) = if self.line.is_empty() {
469+ if self.line.is_empty() {
460− // latest value in the register list
470+ // Show the most recently entered value as a suggestion.
461− match self
471+ if let Some(suggestion) = self
462 .history_register
472 .history_register
463 .and_then(|reg| cx.editor.registers.last(reg))
473 .and_then(|reg| cx.editor.registers.last(reg))
464− .map(|entry| entry.into())
466− Some(value) => (value, true),
475+ surface.set_string(line_area.x, line_area.y, suggestion, suggestion_color);
467− None => (Cow::from(""), false),
477+ } else if let Some((language, loader)) = self.language.as_ref() {
478+ let mut text: ui::text::Text = crate::ui::markdown::highlighted_code_block(
481+ Some(&cx.editor.theme),
486+ text.render(line_area, surface, cx);
470− (self.line.as_str().into(), false)
473− surface.set_string(
488+ surface.set_string(line_area.x, line_area.y, self.line.clone(), prompt_color);
474− area.x + self.prompt.len() as u16,
489+ }