Skip to content

Commit

Permalink
Move cursor by Unicode character count, not byte count. (#107) (#108)
Browse files Browse the repository at this point in the history
* Move cursor by Unicode character count, not byte count. (#107)

* Fix lint errors

* Start new release appdata
  • Loading branch information
santileortiz authored and Jeremy Wootten committed Dec 10, 2019
1 parent 5c3442e commit 5774520
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions data/io.elementary.calculator.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
<p>A simple calculator for everyday use. It supports basic and some scientific calculations including trigonometry functions, sin, cos, and tan.</p>
</description>
<releases>
<release version="Unreleased" date="Future" urgency="medium">

This comment has been minimized.

Copy link
@decathorpe

decathorpe Dec 11, 2019

Contributor

Please don't add bogus entries like this into the appdata file. This makes it invalid (at least for the mandatory validation for fedora packages, which use libappstream-glib).

This comment has been minimized.

Copy link
@jeremypw

jeremypw Dec 11, 2019

Collaborator

OK, thanks for letting me know. What should be entered? The intention is to pre-prepare release information.

This comment has been minimized.

Copy link
@jeremypw

jeremypw Dec 11, 2019

Collaborator

Obviously, before release, valid date and version info would be entered.

This comment has been minimized.

Copy link
@decathorpe

decathorpe Dec 11, 2019

Contributor

@jeremypw other elementary Projects use the "projected" next release version, I'm not sure about the date part though.

See https://github.com/elementary/gala/blob/master/data/gala.appdata.xml.in#L13 for an example.

I'd use placeholder values that sort correctly for both, and, if necessary, adjust them with the Release PR.

@danrabbit, what's the correct way to do this?

<description>
<ul>
<li>Fix inserting multi-byte characters</li>
</ul>
</description>
</release>
<release version="1.5.4" date="2019-11-24" urgency="medium">
<description>
<ul>
Expand Down
6 changes: 3 additions & 3 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,21 @@ namespace PantheonCalculator {
new_position -= selection_length;
}
entry.insert_at_cursor (label);
new_position += label.length;
new_position += label.char_count ();
entry.grab_focus ();
entry.set_position (new_position);
}

private void function_button_clicked (string label) {
int selection_start = -1;
int selection_end = -1;
int new_position = entry.get_position ();
if (entry.get_selection_bounds (out selection_start, out selection_end)) {
int new_position = selection_start;
string selected_text = entry.get_chars (selection_start, selection_end);
string function_call = label + "(" + selected_text + ")";
entry.delete_text (selection_start, selection_end);
entry.insert_text (function_call, -1, ref selection_start);
new_position += function_call.length;
new_position += function_call.char_count ();
entry.grab_focus ();
entry.set_position (new_position);
} else {
Expand Down

0 comments on commit 5774520

Please sign in to comment.