documents and editor: a writing view - measure, font, scale, focus fading, typewriter centering
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e89fb32f43
commit
508fee9d15
13 files changed
+299
-12
No files matched your search
@@ -33,6 +33,7 @@ mod tasks;
|
||||
mod tests;
|
||||
mod view;
|
||||
mod welcome;
|
||||
mod writing;
|
||||
|
||||
pub use buffer::Buffer;
|
||||
pub use chat::InlineChat;
|
||||
|
||||
@@ -11,6 +11,9 @@ use super::{
|
||||
};
|
||||
use crate::theme::{ActiveTheme, TextSize};
|
||||
|
||||
/// How far a faded line recedes.
|
||||
const FADED: f32 = 0.35;
|
||||
|
||||
impl CodeEditor {
|
||||
/// Row `ix` as the list draws it.
|
||||
pub(crate) fn row(&self, ix: usize, window: &mut Window, cx: &mut Context<Self>) -> AnyElement {
|
||||
@@ -19,7 +22,11 @@ impl CodeEditor {
|
||||
.w_full()
|
||||
.h(self.frame.line)
|
||||
.flex();
|
||||
let caret = self.buffer.line_of(self.primary().head);
|
||||
match self.frame.rows[ix] {
|
||||
Row::Line(line) if self.options.focus_line && line != caret => {
|
||||
self.line_row(base.opacity(FADED), ix, line, window, cx)
|
||||
}
|
||||
Row::Line(line) => self.line_row(base, ix, line, window, cx),
|
||||
Row::Lens(at) => self.lens_row(base, ix, at, cx),
|
||||
Row::Removed(hunk, at) => self.removed_row(base, ix, hunk, at, cx),
|
||||
|
||||
@@ -64,6 +64,12 @@ pub(crate) struct Options {
|
||||
pub read_only: bool,
|
||||
pub tab: usize,
|
||||
pub highlighter: Option<super::prose::LineHighlighter>,
|
||||
/// Text size against the theme's.
|
||||
pub scale: f32,
|
||||
/// Lines but the caret's fade.
|
||||
pub focus_line: bool,
|
||||
/// The caret's line stays mid-view.
|
||||
pub typewriter: bool,
|
||||
}
|
||||
|
||||
/// What the owner lays over the code.
|
||||
@@ -114,6 +120,8 @@ pub struct CodeEditor {
|
||||
/// The text before an input method's composition began, while it runs.
|
||||
pub(crate) composing: Option<Snapshot>,
|
||||
pub(crate) metrics: Metrics,
|
||||
/// The caret row typewriter scrolling last centered.
|
||||
pub(crate) centered: Option<usize>,
|
||||
pub(crate) dragging: bool,
|
||||
pub(crate) caret_on: bool,
|
||||
/// Blink runs only while focused, or unseen cursors redraw forever.
|
||||
@@ -191,11 +199,15 @@ impl CodeEditor {
|
||||
read_only: false,
|
||||
tab: 4,
|
||||
highlighter: None,
|
||||
scale: 1.0,
|
||||
focus_line: false,
|
||||
typewriter: false,
|
||||
},
|
||||
marks: Marks::default(),
|
||||
marked: None,
|
||||
composing: None,
|
||||
metrics: Metrics::default(),
|
||||
centered: None,
|
||||
dragging: false,
|
||||
caret_on: true,
|
||||
focused: false,
|
||||
|
||||
+10
-3
@@ -2,8 +2,8 @@ use std::ops::Range;
|
||||
|
||||
use gpui::{
|
||||
AnyElement, Bounds, Context, ElementInputHandler, InteractiveElement, IntoElement, MouseButton,
|
||||
MouseDownEvent, MouseMoveEvent, ParentElement, Pixels, Render, Styled, StyledText, Window,
|
||||
canvas, div, fill, font, point, size, uniform_list,
|
||||
MouseDownEvent, MouseMoveEvent, ParentElement, Pixels, Render, ScrollStrategy, Styled,
|
||||
StyledText, Window, canvas, div, fill, font, point, size, uniform_list,
|
||||
};
|
||||
|
||||
use super::{
|
||||
@@ -225,7 +225,7 @@ impl Render for CodeEditor {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors.clone();
|
||||
let mono_family = theme.mono_family.clone();
|
||||
let size = theme.text_size(TextSize::Sm);
|
||||
let size = theme.text_size(TextSize::Sm) * self.options.scale;
|
||||
let pixels = size.to_pixels(window.rem_size());
|
||||
let mono = window
|
||||
.text_system()
|
||||
@@ -263,6 +263,13 @@ impl Render for CodeEditor {
|
||||
};
|
||||
self.metrics.advance = advance;
|
||||
self.metrics.line = line;
|
||||
// Typewriter: the caret's row centers as it moves.
|
||||
let row = self.primary_row();
|
||||
if self.options.typewriter && self.centered != Some(row) {
|
||||
self.scroll
|
||||
.scroll_to_item_strict(row, ScrollStrategy::Center);
|
||||
self.centered = Some(row);
|
||||
}
|
||||
let sticky = if self.options.sticky {
|
||||
self.sticky(cx)
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//! Settings for a writing view over the code.
|
||||
|
||||
use gpui::Context;
|
||||
|
||||
use super::CodeEditor;
|
||||
|
||||
impl CodeEditor {
|
||||
/// Text size against the theme's, for a writing view.
|
||||
pub fn set_scale(&mut self, scale: f32, cx: &mut Context<Self>) {
|
||||
self.options.scale = scale;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Fades every line but the caret's.
|
||||
pub fn set_focus_line(&mut self, on: bool, cx: &mut Context<Self>) {
|
||||
self.options.focus_line = on;
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Keeps the caret's line mid-view.
|
||||
pub fn set_typewriter(&mut self, on: bool, cx: &mut Context<Self>) {
|
||||
self.options.typewriter = on;
|
||||
self.centered = None;
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user