部分选词后,已选汉字同时存在于 composition 范围和 word_for_creating_word。 标点提交只组装「候选 + 标点」并整段替换该范围,已选汉字就随范围一起消失了。 Enter 和中英文切换都已经带上前缀,标点是同一族里唯一漏掉的一处。 前缀只加在写进 composition 的文本上:成对标点、智能标点指纹和 _NoteCommittedChinesePunctuation 仍读未加前缀的串,标点自身的选取不受影响。 #747
52 lines
1.7 KiB
C++
52 lines
1.7 KiB
C++
#include "Key/PunctuationCommitText.h"
|
||
|
||
#include <string>
|
||
|
||
int main()
|
||
{
|
||
// Do not use assert: Release builds must execute these checks too.
|
||
|
||
// #747: selecting 你 out of nihao leaves hao in the composition, and the
|
||
// highlighted candidate only answers for hao. The selected prefix has to
|
||
// ride along with the punctuation or it is dropped with the range.
|
||
if (BuildPunctuationCommitText(L"你", L"好,") != L"你好,")
|
||
{
|
||
return 1;
|
||
}
|
||
// Remaining raw emptied but the created word still alive: pure punctuation.
|
||
if (BuildPunctuationCommitText(L"你", L",") != L"你,")
|
||
{
|
||
return 2;
|
||
}
|
||
// Numpad '.' keeps its ASCII form but still carries the selection.
|
||
if (BuildPunctuationCommitText(L"你", L".") != L"你.")
|
||
{
|
||
return 3;
|
||
}
|
||
// Nothing was selected: this must return the same bytes it was handed, so
|
||
// every ordinary punctuation commit keeps behaving exactly as before.
|
||
if (BuildPunctuationCommitText(L"", L"。") != L"。")
|
||
{
|
||
return 4;
|
||
}
|
||
if (BuildPunctuationCommitText(L"", L"") != L"")
|
||
{
|
||
return 5;
|
||
}
|
||
// The prefix goes in front and never replaces the punctuation: the last
|
||
// character is still what the punctuation key resolved to, which is what
|
||
// the paired-punctuation and reversible-space decisions read.
|
||
const std::wstring quoted = BuildPunctuationCommitText(L"北京", L"“");
|
||
if (quoted != L"北京“" || quoted.back() != L'“' || quoted.size() != std::wstring(L"北京").size() + 1)
|
||
{
|
||
return 6;
|
||
}
|
||
// A selection with no punctuation text still commits the selection.
|
||
if (BuildPunctuationCommitText(L"你好", L"") != L"你好")
|
||
{
|
||
return 7;
|
||
}
|
||
|
||
return 0;
|
||
}
|