Skip to content

Commit

Permalink
Copy annotation when adding candidate to candidate-list
Browse files Browse the repository at this point in the history
  • Loading branch information
ueno committed Sep 17, 2014
1 parent 5c40313 commit 1debd7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions libkkc/candidate-list.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace Kkc {
}
}

Set<string> seen = new Gee.HashSet<string> ();
Map<string, Candidate> seen = new Gee.HashMap<string, Candidate> ();

internal void clear () {
bool is_populated = false;
Expand Down Expand Up @@ -94,12 +94,18 @@ namespace Kkc {
}

internal bool add (Candidate candidate) {
if (!(candidate.output in seen)) {
if (candidate.output in seen) {
var c = seen.get (candidate.output);
// If the given candidate has annotation and the
// existing one doesn't, copy it.
if (c.annotation == null && candidate.annotation != null)
c.annotation = candidate.annotation;
return false;
} else {
_candidates.add (candidate);
seen.add (candidate.output);
seen.set (candidate.output, candidate);
return true;
}
return false;
}

internal bool add_all (CandidateList other) {
Expand Down
11 changes: 11 additions & 0 deletions tests/context.vala
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ class ContextTests : Kkc.TestCase {
context.reset ();
context.clear_output ();

try {
context.process_key_events ("a i SPC RET a i SPC SPC");
} catch (Kkc.KeyEventFormatError e) {
assert_not_reached ();
}
assert (context.candidates.size > 0);
assert (context.candidates.get (0).output == "");
assert (context.candidates.get (0).annotation == "a");
context.reset ();
context.clear_output ();

try {
context.process_key_events ("k C-g");
} catch (Kkc.KeyEventFormatError e) {
Expand Down

0 comments on commit 1debd7a

Please sign in to comment.