mirror of
https://github.com/chylex/IntelliJ-AceJump.git
synced 2025-04-09 17:15:43 +02:00
[WIP] Add quick jump mode
This commit is contained in:
parent
bfe0aa536e
commit
bce9a5f636
@ -63,4 +63,4 @@ intellij {
|
||||
}
|
||||
|
||||
group = "org.acejump"
|
||||
version = "chylex-1"
|
||||
version = "chylex-2"
|
||||
|
@ -31,10 +31,17 @@ sealed class AceKeyboardAction : DumbAwareAction() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts or ends an AceJump session.
|
||||
* Starts or cycles main AceJump modes.
|
||||
*/
|
||||
object ActivateAceJump : AceKeyboardAction() {
|
||||
override fun invoke(session: Session) = session.cycleMode()
|
||||
override fun invoke(session: Session) = session.startOrCycleMode()
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts or ends an AceJump session in quick jump mode.
|
||||
*/
|
||||
object StartQuickJumpMode : AceKeyboardAction() {
|
||||
override fun invoke(session: Session) = session.startQuickJumpMode()
|
||||
}
|
||||
|
||||
// @formatter:off
|
||||
|
@ -80,6 +80,10 @@ class BetweenPointsMode : SessionMode {
|
||||
return TypeResult.EndSession
|
||||
}
|
||||
|
||||
override fun accept(state: SessionState, acceptedTag: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getHint(acceptedTag: Int?, hasQuery: Boolean): Array<String>? {
|
||||
return when {
|
||||
actionMode == null -> ACTION_MODE_HINT
|
||||
|
@ -69,6 +69,10 @@ class JumpMode : SessionMode {
|
||||
return TypeResult.Nothing
|
||||
}
|
||||
|
||||
override fun accept(state: SessionState, acceptedTag: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getHint(acceptedTag: Int?, hasQuery: Boolean): Array<String>? {
|
||||
return ALL_HINTS.takeIf { acceptedTag != null }
|
||||
}
|
||||
|
27
src/main/kotlin/org/acejump/modes/QuickJumpMode.kt
Normal file
27
src/main/kotlin/org/acejump/modes/QuickJumpMode.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package org.acejump.modes
|
||||
|
||||
import org.acejump.action.AceTagAction
|
||||
import org.acejump.config.AceConfig
|
||||
import org.acejump.session.SessionState
|
||||
import org.acejump.session.TypeResult
|
||||
|
||||
class QuickJumpMode : SessionMode {
|
||||
override val caretColor
|
||||
get() = AceConfig.jumpModeColor
|
||||
|
||||
private var wasUpperCase = false
|
||||
|
||||
override fun type(state: SessionState, charTyped: Char, acceptedTag: Int?): TypeResult {
|
||||
wasUpperCase = charTyped.isUpperCase()
|
||||
return state.type(charTyped)
|
||||
}
|
||||
|
||||
override fun accept(state: SessionState, acceptedTag: Int): Boolean {
|
||||
state.act(AceTagAction.JumpToSearchStart, acceptedTag, wasUpperCase)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun getHint(acceptedTag: Int?, hasQuery: Boolean): Array<String>? {
|
||||
return null
|
||||
}
|
||||
}
|
@ -23,6 +23,10 @@ class SelectFromCaretMode : SessionMode {
|
||||
return TypeResult.EndSession
|
||||
}
|
||||
|
||||
override fun accept(state: SessionState, acceptedTag: Int): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun getHint(acceptedTag: Int?, hasQuery: Boolean): Array<String>? {
|
||||
return JumpMode.JUMP_ALT_HINT.takeIf { acceptedTag != null }
|
||||
}
|
||||
|
@ -8,5 +8,6 @@ interface SessionMode {
|
||||
val caretColor: Color
|
||||
|
||||
fun type(state: SessionState, charTyped: Char, acceptedTag: Int?): TypeResult
|
||||
fun accept(state: SessionState, acceptedTag: Int): Boolean
|
||||
fun getHint(acceptedTag: Int?, hasQuery: Boolean): Array<String>?
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import org.acejump.input.EditorKeyListener
|
||||
import org.acejump.input.KeyLayoutCache
|
||||
import org.acejump.modes.BetweenPointsMode
|
||||
import org.acejump.modes.JumpMode
|
||||
import org.acejump.modes.QuickJumpMode
|
||||
import org.acejump.modes.SessionMode
|
||||
import org.acejump.search.*
|
||||
import org.acejump.view.TagCanvas
|
||||
@ -90,6 +91,11 @@ class Session(private val editor: Editor) {
|
||||
val offset = result.offset
|
||||
acceptedTag = offset
|
||||
textHighlighter.renderFinal(offset, processor.query)
|
||||
|
||||
if (state?.let { mode.accept(it, offset) } == true) {
|
||||
end()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
is TaggingResult.Mark -> {
|
||||
@ -123,7 +129,7 @@ class Session(private val editor: Editor) {
|
||||
HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, flags, 0, true, info)
|
||||
}
|
||||
|
||||
fun cycleMode() {
|
||||
fun startOrCycleMode() {
|
||||
if (!this::mode.isInitialized) {
|
||||
setMode(JumpMode())
|
||||
state = SessionStateImpl(editor, tagger)
|
||||
@ -139,6 +145,20 @@ class Session(private val editor: Editor) {
|
||||
state = SessionStateImpl(editor, tagger)
|
||||
}
|
||||
|
||||
fun startQuickJumpMode() {
|
||||
if (this::mode.isInitialized && mode is QuickJumpMode) {
|
||||
end()
|
||||
return
|
||||
}
|
||||
|
||||
if (this::mode.isInitialized) {
|
||||
restart()
|
||||
}
|
||||
|
||||
setMode(QuickJumpMode())
|
||||
state = SessionStateImpl(editor, tagger)
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
|
||||
*/
|
||||
|
@ -52,6 +52,9 @@
|
||||
<keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="ctrl shift SEMICOLON"/>
|
||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift SEMICOLON"/>
|
||||
</action>
|
||||
<action id="AceQuickJumpAction"
|
||||
class="org.acejump.action.AceKeyboardAction$StartQuickJumpMode"
|
||||
text="Activate AceJump in Quick Jump Mode"/>
|
||||
<action id="AceLineStartsAction"
|
||||
class="org.acejump.action.AceKeyboardAction$StartAllLineStartsMode"
|
||||
text="Start AceJump in All Line Starts Mode"/>
|
||||
|
Loading…
Reference in New Issue
Block a user