-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/text/src/TextField/usecase/TextFieldSelectedFocusMoveUseCase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import type { TextField } from "../../TextField"; | ||
import { execute as textFieldGetTextDataUseCase } from "./TextFieldGetTextDataUseCase"; | ||
|
||
/** | ||
* @description テキストフィールドの選択中のテキスト位置にスクロールを移動します。 | ||
* Move the scroll to the selected text position in the text field. | ||
* | ||
* @param {TextField} text_field | ||
* @return {void} | ||
* @method | ||
* @protected | ||
*/ | ||
export const execute = (text_field: TextField): void => | ||
{ | ||
if (text_field.selectIndex === -1) { | ||
return ; | ||
} | ||
|
||
const textData = textFieldGetTextDataUseCase(text_field); | ||
if (2 > textData.textTable.length) { | ||
return ; | ||
} | ||
|
||
const textObject = textData.textTable[text_field.selectIndex]; | ||
if (!textObject) { | ||
return ; | ||
} | ||
|
||
const line = textObject.mode === "text" | ||
? textObject.line | ||
: textObject.line - 1; | ||
|
||
const width = text_field.width; | ||
const scaleX = (text_field.textWidth - width) / width; | ||
|
||
let textWidth = 2; | ||
let limitWidth = text_field.scrollX * scaleX - 2 + width; | ||
for (let idx = 1; text_field.selectIndex >= idx; ++idx) { | ||
|
||
const textObject = textData.textTable[idx]; | ||
if (!textObject || textObject.line > line) { | ||
break; | ||
} | ||
|
||
if (textObject.line !== line) { | ||
continue; | ||
} | ||
|
||
if (text_field.selectIndex !== idx) { | ||
textWidth += textObject.w; | ||
} | ||
|
||
limitWidth -= textObject.w; | ||
if (limitWidth > 0) { | ||
continue; | ||
} | ||
|
||
if (text_field.yScrollShape.hasLocalVariable("job")) { | ||
text_field.yScrollShape.deleteLocalVariable("job"); | ||
} | ||
text_field.scrollX += textObject.w / scaleX; | ||
|
||
break; | ||
} | ||
|
||
const scrollWidth = text_field.scrollX * scaleX - 2; | ||
if (scrollWidth > textWidth) { | ||
if (text_field.yScrollShape.hasLocalVariable("job")) { | ||
text_field.yScrollShape.deleteLocalVariable("job"); | ||
} | ||
|
||
text_field.scrollX = text_field.width * ((textWidth - 2) / text_field.textWidth); | ||
|
||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters