improve: range style callback and inactive cursor style #204
This commit is contained in:
@@ -12,6 +12,7 @@ export type IDrawCursorOption = ICursorOption &
|
|||||||
{
|
{
|
||||||
isShow?: boolean;
|
isShow?: boolean;
|
||||||
isBlink?: boolean;
|
isBlink?: boolean;
|
||||||
|
isFocus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Cursor {
|
export class Cursor {
|
||||||
@@ -47,6 +48,10 @@ export class Cursor {
|
|||||||
return this.cursorAgent.getAgentCursorDom()
|
return this.cursorAgent.getAgentCursorDom()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getAgentIsActive(): boolean {
|
||||||
|
return this.getAgentDom() === document.activeElement
|
||||||
|
}
|
||||||
|
|
||||||
public getAgentDomValue(): string {
|
public getAgentDomValue(): string {
|
||||||
return this.getAgentDom().value
|
return this.getAgentDom().value
|
||||||
}
|
}
|
||||||
@@ -86,7 +91,8 @@ export class Cursor {
|
|||||||
color,
|
color,
|
||||||
width,
|
width,
|
||||||
isShow = true,
|
isShow = true,
|
||||||
isBlink = true
|
isBlink = true,
|
||||||
|
isFocus = true
|
||||||
} = { ...cursor, ...payload }
|
} = { ...cursor, ...payload }
|
||||||
// 设置光标代理
|
// 设置光标代理
|
||||||
const height = this.draw.getHeight()
|
const height = this.draw.getHeight()
|
||||||
@@ -99,10 +105,12 @@ export class Cursor {
|
|||||||
const offsetHeight = metrics.height / 4
|
const offsetHeight = metrics.height / 4
|
||||||
const cursorHeight = metrics.height + offsetHeight * 2
|
const cursorHeight = metrics.height + offsetHeight * 2
|
||||||
const agentCursorDom = this.cursorAgent.getAgentCursorDom()
|
const agentCursorDom = this.cursorAgent.getAgentCursorDom()
|
||||||
|
if (isFocus) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
agentCursorDom.focus()
|
agentCursorDom.focus()
|
||||||
agentCursorDom.setSelectionRange(0, 0)
|
agentCursorDom.setSelectionRange(0, 0)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
// fillText位置 + 文字基线到底部距离 - 模拟光标偏移量
|
// fillText位置 + 文字基线到底部距离 - 模拟光标偏移量
|
||||||
const descent = metrics.boundingBoxDescent < 0 ? 0 : metrics.boundingBoxDescent
|
const descent = metrics.boundingBoxDescent < 0 ? 0 : metrics.boundingBoxDescent
|
||||||
const cursorTop = (leftTop[1] + ascent) + descent - (cursorHeight - offsetHeight) + preY
|
const cursorTop = (leftTop[1] + ascent) + descent - (cursorHeight - offsetHeight) + preY
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export class GlobalEvent {
|
|||||||
)
|
)
|
||||||
if (outerEditorDom) {
|
if (outerEditorDom) {
|
||||||
this.setRangeStyle()
|
this.setRangeStyle()
|
||||||
|
this.watchCursorActive()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.cursor.recoveryCursor()
|
this.cursor.recoveryCursor()
|
||||||
@@ -103,6 +104,20 @@ export class GlobalEvent {
|
|||||||
this.range.setRangeStyle()
|
this.range.setRangeStyle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public watchCursorActive() {
|
||||||
|
// 选区闭合&实际光标移出光标代理
|
||||||
|
if (!this.range.getIsCollapsed()) return
|
||||||
|
setTimeout(() => {
|
||||||
|
// 将模拟光标变成失活显示状态
|
||||||
|
if (!this.cursor?.getAgentIsActive()) {
|
||||||
|
this.cursor?.drawCursor({
|
||||||
|
isFocus: false,
|
||||||
|
isBlink: false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public setPageScale = (evt: WheelEvent) => {
|
public setPageScale = (evt: WheelEvent) => {
|
||||||
if (!evt.ctrlKey) return
|
if (!evt.ctrlKey) return
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
|
|||||||
@@ -226,7 +226,8 @@ export class RangeManager {
|
|||||||
public setRangeStyle() {
|
public setRangeStyle() {
|
||||||
if (!this.listener.rangeStyleChange) return
|
if (!this.listener.rangeStyleChange) return
|
||||||
// 结束光标位置
|
// 结束光标位置
|
||||||
const { endIndex, isCrossRowCol } = this.range
|
const { startIndex, endIndex, isCrossRowCol } = this.range
|
||||||
|
if (!~startIndex && !~endIndex) return
|
||||||
let curElement: IElement | null
|
let curElement: IElement | null
|
||||||
if (isCrossRowCol) {
|
if (isCrossRowCol) {
|
||||||
// 单元格选择以当前表格定位
|
// 单元格选择以当前表格定位
|
||||||
|
|||||||
Reference in New Issue
Block a user