mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 10:18:15 +09:00
HackStudio: Indicate git changes in the editor's gutter
"+" for added lines, "!" for changed, "-" for removed.
This commit is contained in:
parent
8501617fcb
commit
d5828dbecb
Notes:
sideshowbarker
2024-07-18 12:19:11 +09:00
Author: https://github.com/dmitrii-ubskii
Commit: d5828dbecb
Pull-request: https://github.com/SerenityOS/serenity/pull/8016
4 changed files with 71 additions and 0 deletions
|
@ -121,6 +121,7 @@ void Editor::paint_event(GUI::PaintEvent& event)
|
|||
if (gutter_visible()) {
|
||||
size_t first_visible_line = text_position_at(event.rect().top_left()).line();
|
||||
size_t last_visible_line = text_position_at(event.rect().bottom_right()).line();
|
||||
|
||||
for (size_t line : breakpoint_lines()) {
|
||||
if (line < first_visible_line || line > last_visible_line) {
|
||||
continue;
|
||||
|
@ -132,6 +133,31 @@ void Editor::paint_event(GUI::PaintEvent& event)
|
|||
const auto& icon = current_position_icon_bitmap();
|
||||
painter.blit(gutter_icon_rect(execution_position().value()).top_left(), icon, icon.rect());
|
||||
}
|
||||
|
||||
if (wrapper().git_repo()) {
|
||||
for (auto& hunk : wrapper().hunks()) {
|
||||
auto start_line = hunk.target_start_line;
|
||||
auto finish_line = start_line + hunk.added_lines.size();
|
||||
|
||||
auto additions = hunk.added_lines.size();
|
||||
auto deletions = hunk.removed_lines.size();
|
||||
|
||||
for (size_t line_offset = 0; line_offset < additions; line_offset++) {
|
||||
auto line = start_line + line_offset;
|
||||
if (line < first_visible_line || line > last_visible_line) {
|
||||
continue;
|
||||
}
|
||||
char const* sign = (line_offset < deletions) ? "!" : "+";
|
||||
painter.draw_text(gutter_icon_rect(line), sign, font(), Gfx::TextAlignment::Center);
|
||||
}
|
||||
if (additions < deletions) {
|
||||
auto deletions_line = min(finish_line, line_count() - 1);
|
||||
if (deletions_line <= last_visible_line) {
|
||||
painter.draw_text(gutter_icon_rect(deletions_line), "-", font(), Gfx::TextAlignment::Center);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue