Skip to content

Commit eb86edf

Browse files
committed
Improve input method
1 parent 0782ae6 commit eb86edf

File tree

7 files changed

+399
-41
lines changed

7 files changed

+399
-41
lines changed

editor/cursor.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package editor
22

33
import (
44
"math"
5-
"runtime"
65

76
"github.com/akiyosi/goneovim/util"
87
"github.com/therecipe/qt/core"
@@ -320,10 +319,12 @@ func (c *Cursor) getDrawingPos(x, y, xprime, yprime, deltax, deltay float64) (fl
320319
func (c *Cursor) move() {
321320
X, Y := c.getDrawingPos(c.x, c.y, c.xprime, c.yprime, c.deltax, c.deltay)
322321

323-
c.Move2(
324-
int(X),
325-
int(Y),
326-
)
322+
iX := int(X)
323+
iY := int(Y)
324+
325+
iX += c.ws.screen.tooltip.cursorVisualPos
326+
327+
c.Move2(iX, iY)
327328
}
328329

329330
func (c *Cursor) updateFont(targetWin *Window, font *Font) {
@@ -670,9 +671,7 @@ func (c *Cursor) redraw() {
670671
c.paint()
671672

672673
// Fix #119: Wrong candidate window position when using ibus
673-
if runtime.GOOS == "linux" {
674-
gui.QGuiApplication_InputMethod().Update(core.Qt__ImCursorRectangle)
675-
}
674+
editor.app.InputMethod().Update(core.Qt__ImCursorRectangle)
676675
}
677676

678677
// paint() is to request update cursor widget.

editor/handleime.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "handleime.h"
2+
3+
#include <QInputMethodEvent>
4+
5+
6+
int selectionLengthInPreeditStrOnDarwin(void* ptr, int cursorpos) {
7+
8+
QInputMethodEvent* event = static_cast<QInputMethodEvent*>(ptr);
9+
10+
QList<QInputMethodEvent::Attribute> attributes;
11+
attributes = {};
12+
attributes = event->attributes();
13+
int ret = attributes.size();
14+
15+
for (int i = 0; i < attributes.size(); i++) {
16+
17+
const QInputMethodEvent::Attribute &a = event->attributes().at(i);
18+
19+
if (a.type == QInputMethodEvent::TextFormat) {
20+
21+
if (a.start + a.length == cursorpos) {
22+
ret = a.length;
23+
}
24+
25+
}
26+
27+
}
28+
29+
return ret;
30+
}
31+
32+
int selectionLengthInPreeditStr(void* ptr, int cursorpos) {
33+
34+
QInputMethodEvent* event = static_cast<QInputMethodEvent*>(ptr);
35+
36+
QList<QInputMethodEvent::Attribute> attributes;
37+
attributes = {};
38+
attributes = event->attributes();
39+
int ret = attributes.size();
40+
41+
for (int i = 0; i < attributes.size(); i++) {
42+
43+
const QInputMethodEvent::Attribute &a = event->attributes().at(i);
44+
45+
if (a.type == QInputMethodEvent::TextFormat) {
46+
47+
if (a.start == cursorpos) {
48+
ret = a.length;
49+
}
50+
51+
}
52+
53+
}
54+
55+
return ret;
56+
}
57+
58+
int cursorPosInPreeditStr(void* ptr) {
59+
60+
QInputMethodEvent* event = static_cast<QInputMethodEvent*>(ptr);
61+
62+
63+
QList<QInputMethodEvent::Attribute> attributes;
64+
attributes = {};
65+
attributes = event->attributes();
66+
int ret = attributes.size();
67+
68+
for (int i = 0; i < attributes.size(); i++) {
69+
70+
const QInputMethodEvent::Attribute &a = event->attributes().at(i);
71+
72+
if (a.type == QInputMethodEvent::Cursor) {
73+
74+
ret = a.start;
75+
76+
}
77+
78+
}
79+
80+
return ret;
81+
82+
}

editor/handleime.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package editor
2+
3+
//#include <stdint.h>
4+
//#include "handleime.h"
5+
import "C"
6+
import (
7+
"runtime"
8+
9+
"github.com/therecipe/qt/gui"
10+
)
11+
12+
func selectionPosInPreeditStr(event *gui.QInputMethodEvent) (cursorPos, selectionLength int) {
13+
cursorPos = int(C.cursorPosInPreeditStr(event.Pointer()))
14+
15+
if runtime.GOOS == "darwin" {
16+
selectionLength = int(C.selectionLengthInPreeditStrOnDarwin(event.Pointer(), C.int(cursorPos)))
17+
} else {
18+
selectionLength = int(C.selectionLengthInPreeditStr(event.Pointer(), C.int(cursorPos)))
19+
}
20+
21+
return
22+
}

editor/handleime.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#ifndef GO_HANDLEIME_H
4+
#define GO_HANDLEIME_H
5+
6+
#include <stdint.h>
7+
#include <stdio.h>
8+
9+
#ifdef __cplusplus
10+
extern "C" {
11+
#endif
12+
13+
int selectionLengthInPreeditStr(void* ptr, int cursorpos);
14+
int selectionLengthInPreeditStrOnDarwin(void* ptr, int cursorpos);
15+
int cursorPosInPreeditStr(void* ptr);
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif
20+
21+
#endif

0 commit comments

Comments
 (0)