Skip to content

Commit

Permalink
renpyWarp.syncCursorPosition: reveal the cursor even if the positio…
Browse files Browse the repository at this point in the history
…n has not changed
  • Loading branch information
furudean committed Nov 24, 2024
1 parent 19bb195 commit f7e39f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## Unreleased

- `renpyWarp.syncCursorPosition` will now reveal the cursor even if the position has not changed

## 1.27.1 - 2024-11-24

- There is now a notification rendered when a connection is established or
Expand Down
8 changes: 8 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export function activate(context: vscode.ExtensionContext) {
`current line reported as ${message.relative_path}:${message.line}`
)

if (
![
"Ren'Py updates Visual Studio Code",
'Update both',
].includes(get_config('followCursorMode') as string)
)
return

if (follow_cursor.active_process === process) {
await sync_editor_with_renpy({
path: message.path as string,
Expand Down
22 changes: 8 additions & 14 deletions src/lib/follow_cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,24 @@ export async function sync_editor_with_renpy({
line,
force,
}: SyncEditorWithRenpyOptions): Promise<void> {
if (
!["Ren'Py updates Visual Studio Code", 'Update both'].includes(
get_config('followCursorMode') as string
)
)
return

const warp_spec = `${path}:${line + 1}`
if (!force && warp_spec === last_warps.get(process.pid)) return // no change
last_warps.set(process.pid, warp_spec)

const doc = await vscode.workspace.openTextDocument(path)
const editor = await vscode.window.showTextDocument(doc)

// if the cursor is already on the correct line, don't munge it
if (editor.selection.start.line !== line) {
logger.debug(`syncing editor to ${relative_path}:${line}`)
logger.debug(`syncing editor to ${relative_path}:${line}`)

const end_of_line = editor.document.lineAt(line).range.end.character
const pos = new vscode.Position(line, end_of_line)
const selection = new vscode.Selection(pos, pos)

const end_of_line = editor.document.lineAt(line).range.end.character
const pos = new vscode.Position(line, end_of_line)
const selection = new vscode.Selection(pos, pos)
editor.revealRange(selection)

// if the cursor is already on the correct line, don't munge it
if (editor.selection.start.line !== line) {
editor.selection = selection
editor.revealRange(selection)
}
}

Expand Down

0 comments on commit f7e39f6

Please sign in to comment.