Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework word completion: Start to prepare PrefixNode for dynamic updating #1532

Merged
Merged
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
42 changes: 38 additions & 4 deletions plugins/word-completion/prefix-tree-node.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,50 @@
*/

public class Scratch.Plugins.PrefixNode : Object {
public GLib.List<PrefixNode> children;
public enum NodeType {
ROOT,
CHAR,
WORD_END
}

private const unichar WORD_END_CHAR = '\0';
private uint occurrences; // Only used for WORD_END nodes

public unichar uc { get; construct; }
public NodeType node_type { get; construct; }
public PrefixNode? parent { get; construct; }
public unichar value { get; construct; }

public PrefixNode (unichar c = '\0') {
public Gee.ArrayList<PrefixNode> children;

public PrefixNode.from_unichar (unichar c, PrefixNode? _parent) requires (c != WORD_END_CHAR) {
Object (
value: c
value: c,
parent: _parent,
uc: c,
node_type: NodeType.CHAR
);
}

public PrefixNode.root () {
Object (
parent: null,
uc: WORD_END_CHAR,
node_type: NodeType.ROOT
);
}

public PrefixNode.word_end (PrefixNode _parent) {
Object (
parent: _parent,
uc: WORD_END_CHAR,
node_type: NodeType.WORD_END
);

occurrences = 1;
}

construct {
children = new List<PrefixNode> ();
children = new Gee.ArrayList<PrefixNode> ();
}
}
5 changes: 3 additions & 2 deletions plugins/word-completion/prefix-tree.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ namespace Scratch.Plugins {
}
}

var new_child = new PrefixNode (curr);
node.children.insert_sorted (new_child, (c1, c2) => {
var new_child = new PrefixNode.from_unichar (curr, null);
node.children.insert (0, new_child);
node.children.sort ((c1, c2) => {
if (c1.value > c2.value) {
return 1;
} else if (c1.value == c2.value) {
Expand Down
Loading