Skip to content

Commit

Permalink
看上去修复了联想预选栏字母的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
0312birdzhang committed Mar 13, 2018
1 parent aaba4c7 commit 4a8a039
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
4 changes: 2 additions & 2 deletions libgooglepinyin/src/pinyindecoderservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ void PinyinDecoderService::flushCache()
im_flush_cache();
}

QList<QString> PinyinDecoderService::predictionList(const QString &history)
QList<QString> PinyinDecoderService::predictionList(const QString &history, int fetchSize)
{
QList<QString> predictList;
char16 (*predictItems)[kMaxPredictSize + 1] = 0;
int predictNum = int(im_get_predicts(history.utf16(), predictItems));
predictList.reserve(predictNum);
for (int i = 0; i < predictNum; i++)
for (int i = 0; i <= fetchSize; i++)
predictList.append(QString((QChar *)predictItems[i]));
return predictList;
}
Expand Down
2 changes: 1 addition & 1 deletion libgooglepinyin/src/pinyindecoderservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class PinyinDecoderService : public QObject
int cancelLastChoice();
Q_INVOKABLE int fixedLength();
void flushCache();
Q_INVOKABLE QList<QString> predictionList(const QString &history);
Q_INVOKABLE QList<QString> predictionList(const QString &history, int fetchSize);

private:
static QScopedPointer<PinyinDecoderService> _instance;
Expand Down
57 changes: 30 additions & 27 deletions miaomiaomiao/maliit/plugins/com/jolla/SouniaoHandler.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ InputHandler {
property bool hasMore: composingEnabled && gpy.hasMore
//mod start
property bool pinyinMode: MInputMethodQuick.contentType !== Maliit.UrlContentType && MInputMethodQuick.contentType !== Maliit.EmailContentType

property int cursorIndex: MInputMethodQuick.cursorPosition

onPinyinModeChanged: {
handler.composingEnabled = handler.pinyinMode
Expand All @@ -28,6 +28,12 @@ InputHandler {
reset()
}

onCursorIndexChanged: {
if(pinyinMode){
getPredictions(false);
}
}

onActiveChanged: {
if (active) {
if(pinyinMode){
Expand All @@ -54,7 +60,8 @@ InputHandler {
property var olderSql
property bool hasMore:false
property bool fetchMany:false
property int pageSize:20
property int pageSize: 20 //TODO configroup
property int fetchSize: 15 //TODO configroup
property int pred:0

signal candidatesUpdated
Expand Down Expand Up @@ -569,7 +576,7 @@ InputHandler {

handled = true
} else if (pressedKey.key === Qt.Key_Backspace && preedit == "") {
getPredictions(true);
// getPredictions(true);
} else if (pressedKey.key === Qt.Key_Home) {
MInputMethodQuick.sendKey(Qt.Key_Home, 0, "", Maliit.KeyClick)
} else if (pressedKey.key === Qt.Key_End) {
Expand Down Expand Up @@ -734,36 +741,32 @@ InputHandler {
if (preedit.length > 0 ) {
MInputMethodQuick.sendPreedit(preedit)
}
getPredictions(false);

}


function getPredictions(isDelete){
gpy.candidates.clear();
var tmppredictionsList = [];
if(!isDelete){
tmppredictionsList = gpy.predictionList(
MInputMethodQuick.surroundingText.substring(MInputMethodQuick.cursorPosition-1,
MInputMethodQuick.cursorPosition)
);
}else{
tmppredictionsList = MInputMethodQuick.surroundingText.length > 2 ?
gpy.predictionList(MInputMethodQuick.surroundingText.substring(MInputMethodQuick.cursorPosition-2,
MInputMethodQuick.cursorPosition-1)
):[]
}
preedit = "";
commit(preedit)
gpy.candidates.clear();
var tmppredictionsList = [];
if(!isDelete){
tmppredictionsList = gpy.predictionList(
MInputMethodQuick.surroundingText.substring(MInputMethodQuick.cursorPosition-1,
MInputMethodQuick.cursorPosition),
gpy.fetchSize);
}else{
tmppredictionsList = MInputMethodQuick.surroundingText.length > 2 ?
gpy.predictionList(MInputMethodQuick.surroundingText.substring(MInputMethodQuick.cursorPosition-2,
MInputMethodQuick.cursorPosition-1),
gpy.fetchSize):[]
}

for (var i = 0; i < tmppredictionsList.length; i++) {
// if(i > gpy.pageSize){
// gpy.moreCandidates.append({text: tmppredictionsList[i], type: "partial", segment: 0, candidate: i})
// }else{
gpy.candidates.append({text: tmppredictionsList[i], type: "partial", segment: 0, candidate: i})
// }
}
gpy.hasMore = false;
gpy.candidatesUpdated();
for (var i = 0; i < tmppredictionsList.length; i++) {
gpy.candidates.append({text: tmppredictionsList[i], type: "full", segment: 0, candidate: i})
}
gpy.hasMore = false;
gpy.candidatesUpdated();
}

function isInputCharacter(character) {
return "\'-".indexOf(character) >= 0
Expand Down

0 comments on commit 4a8a039

Please sign in to comment.