Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Services/Document.vala
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ namespace Scratch.Services {
private string last_save_content = "";
public bool saved = true;
private bool completion_shown = false;
private SelectionRange last_selection;

private Gtk.ScrolledWindow scroll;
private Gtk.SourceMap source_map;
Expand Down Expand Up @@ -264,6 +265,8 @@ namespace Scratch.Services {
check_file_status.begin ();
}

restore_selection ();

return false;
});

Expand All @@ -273,6 +276,8 @@ namespace Scratch.Services {
save_with_hold.begin ();
}

save_selection ();

return false;
});

Expand Down Expand Up @@ -1364,5 +1369,33 @@ namespace Scratch.Services {
outline.parse_symbols ();
}
}

// Only call when document is focusing out
private void save_selection () {
Gtk.TextIter start,end;
var source_buffer = (Gtk.SourceBuffer)source_view.buffer;
if (source_buffer.has_selection) {
source_buffer.get_selection_bounds (out start, out end);
last_selection = SelectionRange () {
start_line = start.get_line (),
start_column = start.get_line_offset (),
end_line = end.get_line (),
end_column = end.get_line_offset ()
};
} else {
last_selection = SelectionRange.EMPTY;
}
}

// We assume the selection cannot change while the document is focused out
private void restore_selection () {
if (last_selection != SelectionRange.EMPTY) {
var source_buffer = (Gtk.SourceBuffer)source_view.buffer;
Gtk.TextIter start, end;
source_buffer.get_iter_at_line_offset (out start, last_selection.start_line, last_selection.start_column);
source_buffer.get_iter_at_line_offset (out end, last_selection.end_line, last_selection.end_column);
source_buffer.select_range (start, end);
}
}
}
}
6 changes: 3 additions & 3 deletions src/Services/LocationJumpManager.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
*
* Authored by: Colin Kiama <colinkiama@gmail.com>
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Services/RestoreOverride.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
*
* Authored by: Colin Kiama <colinkiama@gmail.com>
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Structs/SelectionRange.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2023 elementary, Inc. <https://elementary.io>
*
* Authored by: Colin Kiama <colinkiama@gmail.com>
*/
Expand Down