mirror of https://github.com/helix-editor/helix
clean up
parent
7da809a780
commit
ecfce4cd06
|
@ -73,52 +73,6 @@ impl<H: Iterator<Item = HighlightEvent>> Iterator for StyleIter<'_, H> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A wrapper around a HighlightIterator
|
||||
/// that merges the layered highlights to create the final text style
|
||||
/// and yields the active text style and the char_idx where the active
|
||||
/// style will have to be recomputed.
|
||||
struct RawStyleIter<'a, H: Iterator<Item = (Range, Style)>> {
|
||||
text_style: Style,
|
||||
active_highlights: Vec<Highlight>,
|
||||
highlight_iter: H,
|
||||
theme: &'a Theme,
|
||||
}
|
||||
|
||||
impl<H: Iterator<Item = (Range, Style)>> Iterator for RawStyleIter<'_, H> {
|
||||
type Item = (Style, usize);
|
||||
fn next(&mut self) -> Option<(Style, usize)> {
|
||||
while let Some(event) = self.highlight_iter.next() {
|
||||
// let style = self.active_highlights.iter().fold(self.text_style, |acc, span| {
|
||||
// acc.patch(event.1)
|
||||
// });
|
||||
|
||||
return Some((self.text_style.patch(event.1), event.0.head));
|
||||
|
||||
// match event {
|
||||
// HighlightEvent::HighlightStart(highlights) => {
|
||||
// self.active_highlights.push(highlights)
|
||||
// }
|
||||
// HighlightEvent::HighlightEnd => {
|
||||
// self.active_highlights.pop();
|
||||
// }
|
||||
// HighlightEvent::Source { start, end } => {
|
||||
// if start == end {
|
||||
// continue;
|
||||
// }
|
||||
// let style = self
|
||||
// .active_highlights
|
||||
// .iter()
|
||||
// .fold(self.text_style, |acc, span| {
|
||||
// acc.patch(self.theme.highlight(span.0))
|
||||
// });
|
||||
|
||||
// return Some((style, end));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||
pub struct LinePos {
|
||||
|
@ -162,7 +116,6 @@ pub fn render_document(
|
|||
theme,
|
||||
line_decoration,
|
||||
translated_positions,
|
||||
&doc.highlights,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -211,7 +164,6 @@ pub fn render_text<'t>(
|
|||
theme: &Theme,
|
||||
line_decorations: &mut [Box<dyn LineDecoration + '_>],
|
||||
translated_positions: &mut [TranslatedPosition],
|
||||
highlight_overrides: &[(helix_core::Range, Style)],
|
||||
) {
|
||||
let (
|
||||
Position {
|
||||
|
@ -355,169 +307,6 @@ pub fn render_text<'t>(
|
|||
for line_decoration in &mut *line_decorations {
|
||||
line_decoration.render_foreground(renderer, last_line_pos, char_pos);
|
||||
}
|
||||
|
||||
// If we have nothing... don't continue
|
||||
// if highlight_overrides.is_empty() {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// {
|
||||
|
||||
// let (
|
||||
// Position {
|
||||
// row: mut row_off, ..
|
||||
// },
|
||||
// mut char_pos,
|
||||
// ) = visual_offset_from_block(
|
||||
// text,
|
||||
// offset.anchor,
|
||||
// offset.anchor,
|
||||
// text_fmt,
|
||||
// text_annotations,
|
||||
// );
|
||||
// row_off += offset.vertical_offset;
|
||||
|
||||
// let (mut formatter, mut first_visible_char_idx) =
|
||||
// DocumentFormatter::new_at_prev_checkpoint(text, text_fmt, text_annotations, offset.anchor);
|
||||
|
||||
// let mut styles = RawStyleIter {
|
||||
// text_style: renderer.text_style,
|
||||
// active_highlights: Vec::with_capacity(64),
|
||||
// highlight_iter: std::iter::once((
|
||||
// helix_core::Range::new(0, highlight_overrides[0].0.anchor),
|
||||
// Style::default(),
|
||||
// )).chain(highlight_overrides.iter().cloned()),
|
||||
// theme
|
||||
// };
|
||||
// // StyleIter {
|
||||
// // text_style: renderer.text_style,
|
||||
// // active_highlights: Vec::with_capacity(64),
|
||||
// // highlight_iter,
|
||||
// // theme,
|
||||
// // };
|
||||
// // .chain(
|
||||
// // highlight_overrides
|
||||
// // .iter()
|
||||
// // .map(|(range, style)| (*style, range.anchor));
|
||||
// // );
|
||||
|
||||
// let mut last_line_pos = LinePos {
|
||||
// first_visual_line: false,
|
||||
// doc_line: usize::MAX,
|
||||
// visual_line: u16::MAX,
|
||||
// start_char_idx: usize::MAX,
|
||||
// };
|
||||
// let mut is_in_indent_area = true;
|
||||
// let mut last_line_indent_level = 0;
|
||||
// let mut style_span = styles
|
||||
// .next()
|
||||
// .unwrap_or_else(|| (Style::default(), usize::MAX));
|
||||
|
||||
// loop {
|
||||
// // formattter.line_pos returns to line index of the next grapheme
|
||||
// // so it must be called before formatter.next
|
||||
// let doc_line = formatter.line_pos();
|
||||
// let Some((grapheme, mut pos)) = formatter.next() else {
|
||||
// let mut last_pos = formatter.visual_pos();
|
||||
// if last_pos.row >= row_off {
|
||||
// last_pos.col -= 1;
|
||||
// last_pos.row -= row_off;
|
||||
// // check if any positions translated on the fly (like cursor) are at the EOF
|
||||
// translate_positions(
|
||||
// char_pos + 1,
|
||||
// first_visible_char_idx,
|
||||
// translated_positions,
|
||||
// text_fmt,
|
||||
// renderer,
|
||||
// last_pos,
|
||||
// );
|
||||
// }
|
||||
// break;
|
||||
// };
|
||||
|
||||
// // skip any graphemes on visual lines before the block start
|
||||
// if pos.row < row_off {
|
||||
// if char_pos >= style_span.1 {
|
||||
// style_span = if let Some(style_span) = styles.next() {
|
||||
// style_span
|
||||
// } else {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// char_pos += grapheme.doc_chars();
|
||||
// first_visible_char_idx = char_pos + 1;
|
||||
// continue;
|
||||
// }
|
||||
// pos.row -= row_off;
|
||||
|
||||
// // if the end of the viewport is reached stop rendering
|
||||
// if pos.row as u16 >= renderer.viewport.height {
|
||||
// break;
|
||||
// }
|
||||
|
||||
// // apply decorations before rendering a new line
|
||||
// if pos.row as u16 != last_line_pos.visual_line {
|
||||
// if pos.row > 0 {
|
||||
// renderer.draw_indent_guides(last_line_indent_level, last_line_pos.visual_line);
|
||||
// is_in_indent_area = true;
|
||||
// for line_decoration in &mut *line_decorations {
|
||||
// line_decoration.render_foreground(renderer, last_line_pos, char_pos);
|
||||
// }
|
||||
// }
|
||||
// last_line_pos = LinePos {
|
||||
// first_visual_line: doc_line != last_line_pos.doc_line,
|
||||
// doc_line,
|
||||
// visual_line: pos.row as u16,
|
||||
// start_char_idx: char_pos,
|
||||
// };
|
||||
// for line_decoration in &mut *line_decorations {
|
||||
// line_decoration.render_background(renderer, last_line_pos);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // acquire the correct grapheme style
|
||||
// if char_pos >= style_span.1 {
|
||||
// style_span = styles.next().unwrap_or((Style::default(), usize::MAX));
|
||||
// }
|
||||
// char_pos += grapheme.doc_chars();
|
||||
|
||||
// // check if any positions translated on the fly (like cursor) has been reached
|
||||
// translate_positions(
|
||||
// char_pos,
|
||||
// first_visible_char_idx,
|
||||
// translated_positions,
|
||||
// text_fmt,
|
||||
// renderer,
|
||||
// pos,
|
||||
// );
|
||||
|
||||
// let grapheme_style = if let GraphemeSource::VirtualText { highlight } = grapheme.source {
|
||||
// let style = renderer.text_style;
|
||||
// if let Some(highlight) = highlight {
|
||||
// style.patch(theme.highlight(highlight.0))
|
||||
// } else {
|
||||
// style
|
||||
// }
|
||||
// } else {
|
||||
// style_span.0
|
||||
// };
|
||||
|
||||
// let virt = grapheme.is_virtual();
|
||||
// renderer.draw_grapheme(
|
||||
// grapheme.grapheme,
|
||||
// grapheme_style,
|
||||
// virt,
|
||||
// &mut last_line_indent_level,
|
||||
// &mut is_in_indent_area,
|
||||
// pos,
|
||||
// );
|
||||
// }
|
||||
|
||||
// renderer.draw_indent_guides(last_line_indent_level, last_line_pos.visual_line);
|
||||
// for line_decoration in &mut *line_decorations {
|
||||
// line_decoration.render_foreground(renderer, last_line_pos, char_pos);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -224,13 +224,6 @@ impl EditorView {
|
|||
statusline::RenderContext::new(editor, doc, view, is_focused, &self.spinners);
|
||||
|
||||
statusline::render(&mut context, statusline_area, surface);
|
||||
|
||||
// Custom rendering table?
|
||||
// for x in 0..20 {
|
||||
// if let Some(cell) = surface.get_mut(x, 0) {
|
||||
// cell.fg = Color::Green;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn render_rulers(
|
||||
|
@ -809,8 +802,6 @@ impl EditorView {
|
|||
let mut last_mode = mode;
|
||||
self.pseudo_pending.extend(self.keymaps.pending());
|
||||
|
||||
// let key_result = self.keymaps.get(mode, event);
|
||||
|
||||
// Check the engine for any buffer specific keybindings first
|
||||
let key_result = ScriptingEngine::get_keymap_for_extension(cxt)
|
||||
.and_then(|map| {
|
||||
|
|
|
@ -186,11 +186,6 @@ pub struct Document {
|
|||
// when document was used for most-recent-used buffer picker
|
||||
pub focused_at: std::time::Instant,
|
||||
|
||||
// TODO: This is not really something we _want_, but more seeing if it is
|
||||
// enough to get away with custom applications of colors.
|
||||
// Selection -> Style to apply for that selection AFTER rendering.
|
||||
pub highlights: Vec<(Range, crate::graphics::Style)>,
|
||||
|
||||
// A name separate from the file name
|
||||
pub name: Option<String>,
|
||||
pub readonly: bool,
|
||||
|
@ -643,25 +638,6 @@ where
|
|||
use helix_lsp::{lsp, Client, LanguageServerName};
|
||||
use url::Url;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
struct RawHighlight {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
pub style: crate::graphics::Style,
|
||||
}
|
||||
|
||||
impl PartialOrd for RawHighlight {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.end.partial_cmp(&other.start)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for RawHighlight {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
self.end.cmp(&other.start)
|
||||
}
|
||||
}
|
||||
|
||||
impl Document {
|
||||
pub fn from(
|
||||
text: Rope,
|
||||
|
@ -701,10 +677,6 @@ impl Document {
|
|||
config,
|
||||
version_control_head: None,
|
||||
focused_at: std::time::Instant::now(),
|
||||
highlights: vec![(
|
||||
helix_core::Range::new(10, 20),
|
||||
crate::graphics::Style::default().fg(crate::graphics::Color::Green),
|
||||
)],
|
||||
name: None,
|
||||
readonly: false,
|
||||
}
|
||||
|
|
160
helix.scm
160
helix.scm
|
@ -1,160 +0,0 @@
|
|||
(require-builtin helix/core/typable as helix.)
|
||||
(require-builtin helix/core/static as helix.static.)
|
||||
(require-builtin helix/core/keybindings as helix.keybindings.)
|
||||
|
||||
(provide set-theme-dracula
|
||||
set-theme-dracula__doc__
|
||||
set-theme-custom
|
||||
set-theme-custom__doc__
|
||||
theme-then-vsplit
|
||||
theme-then-vsplit__doc__
|
||||
custom-undo
|
||||
custom-undo__doc__
|
||||
lam
|
||||
lam__doc__
|
||||
delete-word-forward
|
||||
insert-string-at-selection
|
||||
highlight-to-matching-paren
|
||||
highlight-to-matching-paren__doc__
|
||||
delete-sexpr
|
||||
delete-sexpr__doc__
|
||||
run-expr
|
||||
run-highlight
|
||||
make-minor-mode!
|
||||
git-status
|
||||
|
||||
reload-helix-scm
|
||||
static-format)
|
||||
|
||||
;;@doc
|
||||
;; Sets the theme to be the dracula theme
|
||||
(define (set-theme-dracula cx)
|
||||
(helix.theme cx (list "dracula") helix.PromptEvent::Validate))
|
||||
|
||||
(enqueue-callback! 'helix.static.format)
|
||||
(enqueue-callback! 'set-theme-dracula)
|
||||
|
||||
;;@doc
|
||||
;; Sets the theme to be the theme passed in
|
||||
(define (set-theme-custom cx entered-theme)
|
||||
(helix.theme cx (list entered-theme) helix.PromptEvent::Validate))
|
||||
|
||||
;;@doc
|
||||
;; Switch theme to the entered theme, then split the current file into
|
||||
;; a vsplit
|
||||
(define (theme-then-vsplit cx entered-theme)
|
||||
(set-theme-custom cx entered-theme)
|
||||
(helix.vsplit cx '() helix.PromptEvent::Validate))
|
||||
|
||||
;;@doc
|
||||
;; Perform an undo
|
||||
(define (custom-undo cx)
|
||||
(helix.static.undo cx))
|
||||
|
||||
;;@doc
|
||||
;; Insert a lambda
|
||||
(define (lam cx)
|
||||
(helix.static.insert_char cx #\λ)
|
||||
(helix.static.insert_mode cx))
|
||||
|
||||
;;@doc
|
||||
;; Insert the string at the selection and go back into insert mode
|
||||
(define (insert-string-at-selection cx str)
|
||||
(helix.static.insert_string cx str)
|
||||
(helix.static.insert_mode cx))
|
||||
|
||||
;;@doc
|
||||
;; Delete the word forward
|
||||
(define (delete-word-forward cx)
|
||||
(helix.static.delete_word_forward cx))
|
||||
|
||||
;;@doc
|
||||
;; Registers a minor mode with the registered modifer and key map
|
||||
;;
|
||||
;; Examples:
|
||||
;; ```scheme
|
||||
;; (make-minor-mode! "+"
|
||||
;; (hash "P" ":lam"))
|
||||
;; ```
|
||||
(define (make-minor-mode! modifier bindings)
|
||||
(~> (hash "normal" (hash modifier bindings))
|
||||
(value->jsexpr-string)
|
||||
(helix.keybindings.set-keybindings!)))
|
||||
|
||||
(define-syntax minor-mode!
|
||||
(syntax-rules (=>)
|
||||
[(minor-mode! modifier (key => function))
|
||||
(make-minor-mode! modifier (minor-mode-cruncher (key => function)))]
|
||||
|
||||
[(minor-mode! modifier (key => (function ...)))
|
||||
(make-minor-mode! modifier (minor-mode-cruncher (key => (function ...))))]
|
||||
|
||||
[(minor-mode! modifier (key => function) remaining ...)
|
||||
(make-minor-mode! modifier (minor-mode-cruncher (key => function) remaining ...))]
|
||||
|
||||
[(minor-mode! modifier (key => (function ...)) remaining ...)
|
||||
(make-minor-mode! modifier (minor-mode-cruncher (key => function) ... remaining ...))]))
|
||||
|
||||
(define-syntax minor-mode-cruncher
|
||||
(syntax-rules (=>)
|
||||
|
||||
[(minor-mode-cruncher (key => (function ...)))
|
||||
(hash key (map (lambda (x) (string-append ":" (symbol->string x))) (quote (function ...))))]
|
||||
|
||||
[(minor-mode-cruncher (key => function))
|
||||
(hash key (string-append ":" (symbol->string (quote function))))]
|
||||
|
||||
[(minor-mode-cruncher (key => (function ...)) remaining ...)
|
||||
(hash-insert (minor-mode-cruncher remaining ...)
|
||||
key
|
||||
(map (lambda (x) (string-append ":" (symbol->string x))) (quote (function ...))))]
|
||||
|
||||
[(minor-mode-cruncher (key => function) remaining ...)
|
||||
(hash-insert (minor-mode-cruncher remaining ...)
|
||||
key
|
||||
(string-append ":" (symbol->string (quote function))))]))
|
||||
|
||||
;;@doc
|
||||
;; Highlight to the matching paren
|
||||
(define (highlight-to-matching-paren cx)
|
||||
(helix.static.select_mode cx)
|
||||
(helix.static.match_brackets cx))
|
||||
|
||||
(define (run-expr cx)
|
||||
(define current-selection (helix.static.current_selection cx))
|
||||
(when (or (equal? "(" current-selection) (equal? ")" current-selection))
|
||||
(highlight-to-matching-paren cx)
|
||||
(helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx))
|
||||
(helix.static.normal_mode cx)))
|
||||
|
||||
(define (run-highlight cx)
|
||||
(helix.static.run-in-engine! cx (helix.static.current-highlighted-text! cx)))
|
||||
|
||||
;;@doc
|
||||
;; Delete the s-expression matching this bracket
|
||||
;; If the current selection is not on a bracket, this is a no-op
|
||||
(define (delete-sexpr cx)
|
||||
(define current-selection (helix.static.current_selection cx))
|
||||
(when (or (equal? "(" current-selection) (equal? ")" current-selection))
|
||||
(highlight-to-matching-paren cx)
|
||||
(helix.static.delete_selection cx)))
|
||||
|
||||
; (minor-mode! "+" ("l" => lam)
|
||||
; ("q" => (set-theme-dracula lam)))
|
||||
|
||||
(minor-mode! "P"
|
||||
("l" => lam)
|
||||
("p" => highlight-to-matching-paren)
|
||||
("d" => delete-sexpr)
|
||||
("r" => run-expr))
|
||||
|
||||
(make-minor-mode! "+" (hash "l" ":lam"))
|
||||
|
||||
(define (git-status cx)
|
||||
(helix.run-shell-command cx '("git" "status") helix.PromptEvent::Validate))
|
||||
|
||||
(minor-mode! "G" ("s" => git-status))
|
||||
|
||||
(define (reload-helix-scm cx)
|
||||
(helix.static.run-in-engine! cx
|
||||
(string-append "(require \"" (helix.static.get-helix.scm-path) "\")")))
|
Loading…
Reference in New Issue