feat: 发布4×4候选与Android手表应用内键盘组件
这个提交包含在:
1 父节点
82aeeba816
当前提交
87aa966a51
86 个文件已更改
+2697
-2975
没有与搜索条件相匹配的文件
@@ -26,6 +26,23 @@ export function digitsOf(text) {
|
||||
return result
|
||||
}
|
||||
export function chars(text){return Array.from(String(text||''))}
|
||||
// Four columns and four row units. Phrases take more width/height, never ellipsis.
|
||||
export function candidatePages(candidates) {
|
||||
const pages=[];let rows=[],usedRows=0,row=null
|
||||
function flushRow(){if(row){rows.push(row);usedRows+=row.units;row=null}}
|
||||
function flushPage(){flushRow();if(rows.length)pages.push(rows);rows=[];usedRows=0}
|
||||
for(const item of candidates){
|
||||
const length=chars(item.word).length
|
||||
const span=length===1?1:length<=4?2:4
|
||||
const units=span===4?Math.max(1,Math.ceil(length/12)):1
|
||||
if(row&&(row.slots+span>4||row.units!==units))flushRow()
|
||||
if(usedRows+units>4)flushPage()
|
||||
if(!row)row={items:[],slots:0,units}
|
||||
row.items.push({item,span});row.slots+=span
|
||||
if(row.slots===4)flushRow()
|
||||
}
|
||||
flushPage();return pages
|
||||
}
|
||||
export function edit(text,cursor,insertion,maxLength) {
|
||||
const value=chars(text), at=Math.max(0,Math.min(value.length,cursor))
|
||||
const room=Math.max(0,maxLength-value.length), added=chars(insertion).slice(0,room)
|
||||
|
||||
在新工单中引用
屏蔽一个用户