mirror of
https://github.com/chylex/IntelliJ-IdeaVim.git
synced 2025-08-18 19:24:55 +02:00
.github
.idea
.teamcity
assets
config
doc
gradle
src
main
antlr
java
com
maddyhome
idea
vim
action
command
common
CharacterPosition.kt
IndentConfig.kt
config
ex
extension
group
handler
helper
icons
key
listener
mark
newapi
option
regexp
statistic
troubleshooting
ui
vimscript
DynamicLoaderStopper.kt
EventFacade.java
PluginStartup.kt
RegisterActions.java
VimBundledDictionaryProvider.kt
VimPlugin.java
VimProjectService.kt
VimTypedActionHandler.kt
VimTypedDelegateHandler.kt
package-info.java
resources
test
verifier
vim-engine
vimscript-info
.editorconfig
.gitignore
AUTHORS.md
CHANGES.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.txt
README.md
build.gradle.kts
gradle.properties
gradlew
gradlew.bat
qodana.sarif.json
qodana.yaml
settings.gradle
31 lines
1.0 KiB
Kotlin
31 lines
1.0 KiB
Kotlin
/*
|
|
* Copyright 2022 The IdeaVim authors
|
|
*
|
|
* Use of this source code is governed by an MIT-style
|
|
* license that can be found in the LICENSE.txt file or at
|
|
* https://opensource.org/licenses/MIT.
|
|
*/
|
|
|
|
package com.maddyhome.idea.vim.common
|
|
|
|
import com.intellij.openapi.editor.Editor
|
|
import com.intellij.openapi.editor.LogicalPosition
|
|
import com.maddyhome.idea.vim.helper.EditorHelper.getLineStartOffset
|
|
|
|
class CharacterPosition(line: Int, col: Int) : LogicalPosition(line, col) {
|
|
fun toOffset(editor: Editor) = getLineStartOffset(editor, line) + column
|
|
|
|
companion object {
|
|
fun fromOffset(editor: Editor, offset: Int): CharacterPosition {
|
|
// logical position "expands" tabs
|
|
val logicalPosition = editor.offsetToLogicalPosition(offset)
|
|
val lineStartOffset = getLineStartOffset(editor, logicalPosition.line)
|
|
return CharacterPosition(logicalPosition.line, offset - lineStartOffset)
|
|
}
|
|
|
|
fun atCaret(editor: Editor): CharacterPosition {
|
|
return fromOffset(editor, editor.caretModel.offset)
|
|
}
|
|
}
|
|
}
|