@@ -2440,29 +2440,47 @@ export class CommandAdapt {
2440
2440
}
2441
2441
2442
2442
public focus ( payload ?: IFocusOption ) {
2443
- const { position = LocationPosition . AFTER , isMoveCursorToVisible = true } =
2444
- payload || { }
2445
- let curIndex = 0
2446
- const rowNo = payload ?. rowNo
2447
- if ( isNumber ( rowNo ) ) {
2443
+ const {
2444
+ position = LocationPosition . AFTER ,
2445
+ isMoveCursorToVisible = true ,
2446
+ rowNo,
2447
+ range
2448
+ } = payload || { }
2449
+ let curIndex = - 1
2450
+ if ( range ) {
2451
+ // 根据选区定位
2452
+ this . range . replaceRange ( range )
2453
+ curIndex =
2454
+ position === LocationPosition . BEFORE ? range . startIndex : range . endIndex
2455
+ } else if ( isNumber ( rowNo ) ) {
2456
+ // 根据行号定位
2448
2457
const rowList = this . draw . getOriginalRowList ( )
2449
2458
curIndex =
2450
2459
position === LocationPosition . BEFORE
2451
2460
? rowList [ rowNo ] ?. startIndex
2452
2461
: rowList [ rowNo + 1 ] ?. startIndex - 1
2462
+ if ( ! isNumber ( curIndex ) ) return
2463
+ this . range . setRange ( curIndex , curIndex )
2453
2464
} else {
2465
+ // 默认文档首尾
2454
2466
curIndex =
2455
2467
position === LocationPosition . BEFORE
2456
2468
? 0
2457
2469
: this . draw . getOriginalMainElementList ( ) . length - 1
2470
+ this . range . setRange ( curIndex , curIndex )
2458
2471
}
2459
- if ( ! isNumber ( curIndex ) ) return
2460
- this . range . setRange ( curIndex , curIndex )
2461
- this . draw . render ( {
2462
- curIndex,
2472
+ // 光标存在且闭合时定位
2473
+ const renderParams : IDrawOption = {
2463
2474
isCompute : false ,
2475
+ isSetCursor : false ,
2464
2476
isSubmitHistory : false
2465
- } )
2477
+ }
2478
+ if ( ~ curIndex && this . range . getIsCollapsed ( ) ) {
2479
+ renderParams . curIndex = curIndex
2480
+ renderParams . isSetCursor = true
2481
+ }
2482
+ this . draw . render ( renderParams )
2483
+ // 移动滚动条到可见区域
2466
2484
if ( isMoveCursorToVisible ) {
2467
2485
const positionList = this . draw . getPosition ( ) . getPositionList ( )
2468
2486
this . draw . getCursor ( ) . moveCursorToVisible ( {
0 commit comments