Skip to content

Commit 841d15e

Browse files
authored
select candidate on touch (#12)
1 parent 5aac76f commit 841d15e

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

keyboard/fcitx.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "nativestreambuf.h"
55
#include <fcitx-utils/event.h>
66
#include <fcitx-utils/eventdispatcher.h>
7-
#include <fcitx/instance.h>
87
#include <filesystem>
98
#include <thread>
109

keyboard/util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
#pragma once
12

23
#include <fcitx-utils/eventdispatcher.h>
4+
#include <fcitx/instance.h>
35
#include <future>
46

7+
extern std::unique_ptr<fcitx::Instance> instance;
58
extern std::unique_ptr<fcitx::EventDispatcher> dispatcher;
69

710
template <class F, class T = std::invoke_result_t<F>>

uipanel/CandidateBar.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import UIKit
2+
import UIPanel
23

34
class CandidateCollectionView: UIView {
45

@@ -70,6 +71,7 @@ extension CandidateCollectionView: UICollectionViewDataSource {
7071

7172
extension CandidateCollectionView: UICollectionViewDelegate {
7273
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
74+
selectCandidate(Int32(indexPath.item))
7375
}
7476
}
7577

uipanel/module.modulemap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module UIPanel {
2+
header "uipanel-public.h"
3+
}

uipanel/uipanel-public.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
3+
void selectCandidate(int index);

uipanel/uipanel.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#include <fcitx/inputpanel.h>
22

33
#include "../iosfrontend/iosfrontend.h"
4+
#include "../keyboard/fcitx.h"
5+
#include "../keyboard/util.h"
46
#include "keyboardui-swift.h"
7+
#include "uipanel-public.h"
58
#include "uipanel.h"
69

710
namespace fcitx {
@@ -40,3 +43,18 @@ void UIPanel::update(UserInterfaceComponent component,
4043
}
4144

4245
} // namespace fcitx
46+
47+
void selectCandidate(int index) {
48+
with_fcitx([index] {
49+
auto ic = instance->mostRecentInputContext();
50+
const auto &list = ic->inputPanel().candidateList();
51+
if (!list)
52+
return;
53+
try {
54+
// Engine is responsible for updating UI
55+
list->candidate(index).select(ic);
56+
} catch (const std::invalid_argument &e) {
57+
FCITX_ERROR() << "select candidate index out of range";
58+
}
59+
});
60+
}

0 commit comments

Comments
 (0)