paint line changes

This commit is contained in:
Dongdong Zhou 2021-09-22 11:08:25 +01:00
parent 461cdaf439
commit 28a7771730
5 changed files with 60 additions and 4 deletions

View File

@ -11,8 +11,8 @@
use druid::{Env, PaintCtx};
use git2::Repository;
use language::{new_highlight_config, new_parser, LapceLanguage};
use lsp_types::SemanticTokensLegend;
use lsp_types::SemanticTokensServerCapabilities;
use lsp_types::{CallHierarchyOptions, SemanticTokensLegend};
use lsp_types::{
CodeActionResponse, Position, Range, TextDocumentContentChangeEvent,
};
@ -200,6 +200,7 @@ pub struct BufferNew {
pub loaded: bool,
pub local: bool,
update_sender: Arc<Sender<UpdateEvent>>,
pub line_changes: HashMap<usize, char>,
revs: Vec<Revision>,
cur_undo: usize,
@ -241,6 +242,7 @@ pub fn new(path: PathBuf, update_sender: Arc<Sender<UpdateEvent>>) -> Self {
dirty: false,
update_sender,
local: false,
line_changes: HashMap::new(),
revs: vec![Revision {
max_undo_so_far: 0,

View File

@ -274,6 +274,7 @@ pub enum LapceUICommand {
tree: Tree,
},
CenterOfWindow,
UpdateBufferLineChanges(BufferId, u64, HashMap<usize, char>),
UpdateLineChanges(BufferId),
PublishDiagnostics(PublishDiagnosticsParams),
UpdateDiffFiles(Vec<PathBuf>),

View File

@ -854,7 +854,7 @@ fn paint_code_actions_hint(
let height = 16.0;
let rect =
Size::new(width, height).to_rect().with_origin(Point::new(
self.width + 5.0,
self.width + 7.6171875 + 3.0,
(line_height - height) / 2.0 + line_height * line as f64
- data.editor.scroll_offset.y,
));
@ -930,7 +930,7 @@ fn layout(
let last_line = data.buffer.last_line() + 1;
let width = 7.6171875;
self.width = (width * last_line.to_string().len() as f64).ceil();
let width = self.width + 26.0;
let width = self.width + 16.0 + width * 2.0;
Size::new(width, bc.max().height)
}
@ -974,6 +974,33 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceEditorViewData, env: &Env) {
.build()
.unwrap();
ctx.draw_text(&text_layout, pos);
if let Some(line_change) = data.buffer.line_changes.get(&line) {
let x = self.width + width;
let y = line as f64 * line_height - scroll_offset.y;
let origin = Point::new(x, y);
let size = Size::new(3.0, line_height);
let rect = Rect::ZERO.with_origin(origin).with_size(size);
match line_change {
'm' => {
ctx.fill(rect, &Color::rgba8(1, 132, 188, 180));
}
'+' => {
ctx.fill(rect, &Color::rgba8(80, 161, 79, 180));
}
'-' => {
let size = Size::new(3.0, 10.0);
let x = self.width + width;
let y = line as f64 * line_height
- size.height / 2.0
- scroll_offset.y;
let origin = Point::new(x, y);
let rect = Rect::ZERO.with_origin(origin).with_size(size);
ctx.fill(rect, &Color::rgba8(228, 86, 73, 180));
}
_ => {}
}
}
}
if *data.main_split.active == self.view_id {

View File

@ -572,7 +572,17 @@ fn handle_notification(
buffer_id,
line_changes,
rev,
} => {}
} => {
self.event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::UpdateBufferLineChanges(
buffer_id,
rev,
line_changes,
),
Target::Widget(self.tab_id),
);
}
Notification::ReloadBuffer {
buffer_id,
new_content,

View File

@ -346,6 +346,22 @@ fn event(
}
ctx.set_handled();
}
LapceUICommand::UpdateBufferLineChanges(
id,
rev,
line_changes,
) => {
for (_, buffer) in data.main_split.open_files.iter_mut() {
if &buffer.id == id {
if buffer.rev == *rev {
let buffer = Arc::make_mut(buffer);
buffer.line_changes = line_changes.to_owned();
}
break;
}
}
ctx.set_handled();
}
LapceUICommand::UpdateSemanticTokens(id, path, rev, tokens) => {
let buffer =
data.main_split.open_files.get_mut(path).unwrap();