Merge lp:~niclasl/scratch/fix-1351611 into lp:~elementary-apps/scratch/scratch

Proposed by Niclas Lockner
Status: Merged
Approved by: xapantu
Approved revision: 1345
Merged at revision: 1345
Proposed branch: lp:~niclasl/scratch/fix-1351611
Merge into: lp:~elementary-apps/scratch/scratch
Diff against target: 30 lines (+11/-9)
1 file modified
src/Widgets/SourceView.vala (+11/-9)
To merge this branch: bzr merge lp:~niclasl/scratch/fix-1351611
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+229611@code.launchpad.net

Commit message

Fix bug #1351611: The text in the sourceview buffer is now set synchronuously.

Description of the change

The text in the sourceview buffer is now set synchronuously.

The cause of the bug was that there was a window from that the content was loaded from file, to that the callback added to the Idle queue was executed where a call to save would clear the file.

A possible scenario where this would happen is:

1. Some files are opened when Scratch is opened
2. A "focus in" event loads the content of the active tab's file. The callback in set_text is queued.
3. The user switches tab, causing a "focus out" event on the old tab which calls save.
4. Save writes the current content of the empty buffer to file and sets the saved state to true
5. The callback gets executed, filling the buffer with the file content
6. The user closes Scratch. Since saved == true, the content in the buffer is not written to the (now empty) file.

Also, I could not find a reason why the buffer text assignment should be done in a Idle callback, so removing it should not introduce a threading issue.

To post a comment you must log in.
Revision history for this message
xapantu (xapantu) wrote :

It looks fine, even if it is hard to test. Removing the idle makes sense.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Widgets/SourceView.vala'
2--- src/Widgets/SourceView.vala 2014-06-26 08:18:30 +0000
3+++ src/Widgets/SourceView.vala 2014-08-05 12:59:13 +0000
4@@ -258,15 +258,17 @@
5 }
6
7 public void set_text (string text, bool opening = true) {
8- GLib.Idle.add (() => {
9- if (opening) buffer.begin_not_undoable_action ();
10- buffer.text = text;
11- if (opening) buffer.end_not_undoable_action ();
12- Gtk.TextIter? start = null;
13- buffer.get_start_iter (out start);
14- buffer.place_cursor (start);
15- return false;
16- });
17+ if (opening)
18+ buffer.begin_not_undoable_action ();
19+
20+ buffer.text = text;
21+
22+ if (opening)
23+ buffer.end_not_undoable_action ();
24+
25+ Gtk.TextIter? start = null;
26+ buffer.get_start_iter (out start);
27+ buffer.place_cursor (start);
28 }
29
30 public void set_language (SourceLanguage lang) {

Subscribers

People subscribed via source and target branches