mirror of
https://github.com/chylex/IntelliJ-AceJump.git
synced 2025-09-15 22:32:11 +02:00
Compare commits
47 Commits
master
...
fa3505b850
Author | SHA1 | Date | |
---|---|---|---|
fa3505b850
|
|||
dacac684f0
|
|||
e627db3a24
|
|||
084d729baa
|
|||
e01edccb5b
|
|||
655ccde60e
|
|||
eb2ea55fb8
|
|||
a6381a2a34
|
|||
e005983d4c
|
|||
8f4d9748ad
|
|||
76c6458ef4
|
|||
2f53e9da6d
|
|||
100001ffca
|
|||
184896a6cb
|
|||
8563400946
|
|||
a07c61a384
|
|||
e072003c5c
|
|||
8062cf5cab
|
|||
9151ee376c
|
|||
19ce1c69fd
|
|||
f2a053505c
|
|||
647cfb14f1
|
|||
c31ba60909
|
|||
9c60a8a4ba
|
|||
1e8b7d7963
|
|||
9157ce19b0
|
|||
9a435feccc
|
|||
c1feb891e4
|
|||
0b6ba62cda
|
|||
dfd5b122a0
|
|||
f2400d134d
|
|||
98997b4d86
|
|||
1e172e9c49
|
|||
01b37c878e | |||
1630c706a9 | |||
041a130c5f | |||
7561bfde36 | |||
724e469f21 | |||
bce9a5f636 | |||
bfe0aa536e | |||
2ca21b8423 | |||
430bcf6883 | |||
092650af81 | |||
2009123114 | |||
de19c0e0b8 | |||
5021a07fb9 | |||
1180547b06 |
24
.gitignore
vendored
24
.gitignore
vendored
@@ -1,21 +1,5 @@
|
|||||||
### JetBrains template
|
/.idea/*
|
||||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
|
!/.idea/runConfigurations
|
||||||
|
|
||||||
## Directory-based project format:
|
/.gradle/
|
||||||
.idea
|
/build/
|
||||||
*.iml
|
|
||||||
|
|
||||||
## Plugin-specific files:
|
|
||||||
# IntelliJ
|
|
||||||
/out/
|
|
||||||
|
|
||||||
### Gradle template
|
|
||||||
.gradle
|
|
||||||
build/
|
|
||||||
|
|
||||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
|
||||||
!gradle-wrapper.jar
|
|
||||||
gradle.properties
|
|
||||||
|
|
||||||
# Mac OS
|
|
||||||
.DS_Store
|
|
||||||
|
105
build.gradle.kts
105
build.gradle.kts
@@ -1,66 +1,51 @@
|
|||||||
import org.jetbrains.changelog.closure
|
@file:Suppress("ConvertLambdaToReference")
|
||||||
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
|
|
||||||
import org.jetbrains.intellij.tasks.PublishTask
|
|
||||||
import org.jetbrains.intellij.tasks.RunIdeTask
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
idea apply true
|
kotlin("jvm") version "1.9.10"
|
||||||
kotlin("jvm") version "1.3.72"
|
id("org.jetbrains.intellij") version "1.16.1"
|
||||||
id("org.jetbrains.intellij") version "0.7.2"
|
|
||||||
id("org.jetbrains.changelog") version "1.1.2"
|
|
||||||
id("com.github.ben-manes.versions") version "0.38.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
withType<KotlinCompile> {
|
|
||||||
kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
named<Zip>("buildPlugin") {
|
|
||||||
dependsOn("test")
|
|
||||||
archiveFileName.set("AceJump.zip")
|
|
||||||
}
|
|
||||||
|
|
||||||
withType<RunIdeTask> {
|
|
||||||
dependsOn("test")
|
|
||||||
findProperty("luginDev")?.let { args = listOf(projectDir.absolutePath) }
|
|
||||||
}
|
|
||||||
|
|
||||||
withType<PublishTask> {
|
|
||||||
val intellijPublishToken: String? by project
|
|
||||||
token(intellijPublishToken)
|
|
||||||
}
|
|
||||||
|
|
||||||
withType<PatchPluginXmlTask> {
|
|
||||||
sinceBuild("201.6668.0")
|
|
||||||
changeNotes({ changelog.getLatest().toHTML() })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
changelog {
|
|
||||||
path = "${project.projectDir}/CHANGES.md"
|
|
||||||
header = closure { "${project.version}" }
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
// gradle-intellij-plugin doesn't attach sources properly for Kotlin :(
|
|
||||||
compileOnly(kotlin("stdlib-jdk8"))
|
|
||||||
// https://github.com/promeG/TinyPinyin
|
|
||||||
implementation("com.github.promeg:tinypinyin:2.0.3")
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
jcenter()
|
|
||||||
}
|
|
||||||
|
|
||||||
intellij {
|
|
||||||
version = "2020.2"
|
|
||||||
pluginName = "AceJump"
|
|
||||||
updateSinceUntilBuild = false
|
|
||||||
setPlugins("java")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "org.acejump"
|
group = "org.acejump"
|
||||||
version = "3.7"
|
version = "chylex-16"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
intellij {
|
||||||
|
version.set("2023.3")
|
||||||
|
updateSinceUntilBuild.set(false)
|
||||||
|
plugins.add("IdeaVIM:chylex-22")
|
||||||
|
|
||||||
|
pluginsRepositories {
|
||||||
|
custom("https://intellij.chylex.com")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
jvmToolchain(17)
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.patchPluginXml {
|
||||||
|
sinceBuild.set("233")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.buildSearchableOptions {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions.freeCompilerArgs = listOf(
|
||||||
|
"-Xjvm-default=all"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
1
gradle.properties
Normal file
1
gradle.properties
Normal file
@@ -0,0 +1 @@
|
|||||||
|
kotlin.stdlib.default.dependency=false
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
294
gradlew
vendored
294
gradlew
vendored
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -17,67 +17,99 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
@@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
@@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
|
|||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=`save "$@"`
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
15
gradlew.bat
vendored
15
gradlew.bat
vendored
@@ -14,7 +14,7 @@
|
|||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
@@ -25,7 +25,8 @@
|
|||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
@@ -1,6 +1,11 @@
|
|||||||
package org.acejump
|
package org.acejump
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.fileEditor.TextEditor
|
||||||
|
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.util.IncorrectOperationException
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||||
|
|
||||||
annotation class ExternalUsage
|
annotation class ExternalUsage
|
||||||
|
|
||||||
@@ -10,6 +15,21 @@ annotation class ExternalUsage
|
|||||||
val Editor.immutableText
|
val Editor.immutableText
|
||||||
get() = this.document.immutableCharSequence
|
get() = this.document.immutableCharSequence
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all open editors in the project.
|
||||||
|
*/
|
||||||
|
val Project.openEditors: List<Editor>
|
||||||
|
get() {
|
||||||
|
return try {
|
||||||
|
FileEditorManagerEx.getInstanceEx(this)
|
||||||
|
.splitters
|
||||||
|
.getSelectedEditors()
|
||||||
|
.mapNotNull { (it as? TextEditor)?.editor }
|
||||||
|
} catch (e: IncorrectOperationException) {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if [this] contains [otherText] at the specified offset.
|
* Returns true if [this] contains [otherText] at the specified offset.
|
||||||
*/
|
*/
|
||||||
@@ -36,7 +56,7 @@ fun CharSequence.countMatchingCharacters(selfOffset: Int, otherText: String): In
|
|||||||
* Determines which characters form a "word" for the purposes of functions below.
|
* Determines which characters form a "word" for the purposes of functions below.
|
||||||
*/
|
*/
|
||||||
val Char.isWordPart
|
val Char.isWordPart
|
||||||
get() = this.isJavaIdentifierPart()
|
get() = this in 'a'..'z' || this.isJavaIdentifierPart()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds index of the first character in a word.
|
* Finds index of the first character in a word.
|
||||||
@@ -56,8 +76,9 @@ inline fun CharSequence.wordStart(pos: Int, isPartOfWord: (Char) -> Boolean = Ch
|
|||||||
*/
|
*/
|
||||||
inline fun CharSequence.wordEnd(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
|
inline fun CharSequence.wordEnd(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
|
||||||
var end = pos
|
var end = pos
|
||||||
|
val limit = length - 1
|
||||||
|
|
||||||
while (end < length - 1 && isPartOfWord(this[end + 1])) {
|
while (end < limit && isPartOfWord(this[end + 1])) {
|
||||||
++end
|
++end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,14 +90,25 @@ inline fun CharSequence.wordEnd(pos: Int, isPartOfWord: (Char) -> Boolean = Char
|
|||||||
*/
|
*/
|
||||||
inline fun CharSequence.wordEndPlus(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
|
inline fun CharSequence.wordEndPlus(pos: Int, isPartOfWord: (Char) -> Boolean = Char::isWordPart): Int {
|
||||||
var end = this.wordEnd(pos, isPartOfWord)
|
var end = this.wordEnd(pos, isPartOfWord)
|
||||||
|
val limit = length - 1
|
||||||
|
|
||||||
while (end < length - 1 && !isPartOfWord(this[end + 1])) {
|
while (end < limit && !isPartOfWord(this[end + 1])) {
|
||||||
++end
|
++end
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end < length - 1 && isPartOfWord(this[end + 1])) {
|
if (end < limit && isPartOfWord(this[end + 1])) {
|
||||||
++end
|
++end
|
||||||
}
|
}
|
||||||
|
|
||||||
return end
|
return end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun MutableMap<Editor, IntArrayList>.clone(): MutableMap<Editor, IntArrayList> {
|
||||||
|
val clone = HashMap<Editor, IntArrayList>(size)
|
||||||
|
|
||||||
|
for ((editor, offsets) in this) {
|
||||||
|
clone[editor] = offsets.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone
|
||||||
|
}
|
||||||
|
@@ -1,71 +0,0 @@
|
|||||||
package org.acejump.action
|
|
||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
|
||||||
import com.intellij.openapi.actionSystem.CommonDataKeys.EDITOR
|
|
||||||
import com.intellij.openapi.project.DumbAwareAction
|
|
||||||
import org.acejump.boundaries.Boundaries
|
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.search.Pattern
|
|
||||||
import org.acejump.session.Session
|
|
||||||
import org.acejump.session.SessionManager
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base class for keyboard-activated actions that create or update an AceJump [Session].
|
|
||||||
*/
|
|
||||||
sealed class AceAction : DumbAwareAction() {
|
|
||||||
final override fun update(action: AnActionEvent) {
|
|
||||||
action.presentation.isEnabled = action.getData(EDITOR) != null
|
|
||||||
}
|
|
||||||
|
|
||||||
final override fun actionPerformed(e: AnActionEvent) {
|
|
||||||
invoke(SessionManager.start(e.getData(EDITOR) ?: return))
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract operator fun invoke(session: Session)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic action type that toggles a specific [JumpMode].
|
|
||||||
*/
|
|
||||||
abstract class BaseToggleJumpModeAction(private val mode: JumpMode) : AceAction() {
|
|
||||||
final override fun invoke(session: Session) = session.toggleJumpMode(mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic action type that starts a regex search.
|
|
||||||
*/
|
|
||||||
abstract class BaseRegexSearchAction(private val pattern: Pattern, private val boundaries: Boundaries) : AceAction() {
|
|
||||||
override fun invoke(session: Session) = session.startRegexSearch(pattern, boundaries)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initiates an AceJump session in the first [JumpMode], or cycles to the next [JumpMode] as defined in configuration.
|
|
||||||
*/
|
|
||||||
object ActivateOrCycleMode : AceAction() {
|
|
||||||
override fun invoke(session: Session) = session.cycleNextJumpMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initiates an AceJump session in the last [JumpMode], or cycles to the previous [JumpMode] as defined in configuration.
|
|
||||||
*/
|
|
||||||
object ActivateOrReverseCycleMode : AceAction() {
|
|
||||||
override fun invoke(session: Session) = session.cyclePreviousJumpMode()
|
|
||||||
}
|
|
||||||
|
|
||||||
// @formatter:off
|
|
||||||
|
|
||||||
object ToggleJumpMode : BaseToggleJumpModeAction(JumpMode.JUMP)
|
|
||||||
object ToggleJumpEndMode : BaseToggleJumpModeAction(JumpMode.JUMP_END)
|
|
||||||
object ToggleTargetMode : BaseToggleJumpModeAction(JumpMode.TARGET)
|
|
||||||
object ToggleDeclarationMode : BaseToggleJumpModeAction(JumpMode.DEFINE)
|
|
||||||
|
|
||||||
object StartAllWordsMode : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
object StartAllWordsBackwardsMode : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.BEFORE_CARET)
|
|
||||||
object StartAllWordsForwardMode : BaseRegexSearchAction(Pattern.ALL_WORDS, StandardBoundaries.AFTER_CARET)
|
|
||||||
object StartAllLineStartsMode : BaseRegexSearchAction(Pattern.LINE_STARTS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
object StartAllLineEndsMode : BaseRegexSearchAction(Pattern.LINE_ENDS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
object StartAllLineIndentsMode : BaseRegexSearchAction(Pattern.LINE_INDENTS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
object StartAllLineMarksMode : BaseRegexSearchAction(Pattern.LINE_ALL_MARKS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
|
|
||||||
// @formatter:on
|
|
||||||
}
|
|
@@ -4,15 +4,13 @@ import com.intellij.openapi.actionSystem.DataContext
|
|||||||
import com.intellij.openapi.editor.Caret
|
import com.intellij.openapi.editor.Caret
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
|
import com.intellij.openapi.editor.actionSystem.EditorActionHandler
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
|
||||||
import org.acejump.search.Pattern
|
|
||||||
import org.acejump.session.Session
|
import org.acejump.session.Session
|
||||||
import org.acejump.session.SessionManager
|
import org.acejump.session.SessionManager
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for keyboard-activated overrides of existing editor actions, that have a different meaning during an AceJump [Session].
|
* Base class for keyboard-activated overrides of existing editor actions, that have a different meaning during an AceJump [Session].
|
||||||
*/
|
*/
|
||||||
sealed class AceEditorAction(private val originalHandler: EditorActionHandler) : EditorActionHandler() {
|
abstract class AceEditorAction(private val originalHandler: EditorActionHandler) : EditorActionHandler() {
|
||||||
final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
|
final override fun isEnabledForCaret(editor: Editor, caret: Caret, dataContext: DataContext?): Boolean {
|
||||||
return SessionManager[editor] != null || originalHandler.isEnabled(editor, caret, dataContext)
|
return SessionManager[editor] != null || originalHandler.isEnabled(editor, caret, dataContext)
|
||||||
}
|
}
|
||||||
@@ -40,23 +38,7 @@ sealed class AceEditorAction(private val originalHandler: EditorActionHandler) :
|
|||||||
override fun run(session: Session) = session.restart()
|
override fun run(session: Session) = session.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectBackward(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
class TagImmediately(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
||||||
override fun run(session: Session) = session.visitPreviousTag()
|
override fun run(session: Session) = session.tagImmediately()
|
||||||
}
|
|
||||||
|
|
||||||
class SelectForward(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
|
||||||
override fun run(session: Session) = session.visitNextTag()
|
|
||||||
}
|
|
||||||
|
|
||||||
class SearchLineStarts(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
|
||||||
override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_STARTS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
}
|
|
||||||
|
|
||||||
class SearchLineEnds(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
|
||||||
override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_ENDS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
}
|
|
||||||
|
|
||||||
class SearchLineIndents(originalHandler: EditorActionHandler) : AceEditorAction(originalHandler) {
|
|
||||||
override fun run(session: Session) = session.startRegexSearch(Pattern.LINE_INDENTS, StandardBoundaries.WHOLE_FILE)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
99
src/main/kotlin/org/acejump/action/AceTagAction.kt
Normal file
99
src/main/kotlin/org/acejump/action/AceTagAction.kt
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
package org.acejump.action
|
||||||
|
|
||||||
|
import com.intellij.openapi.actionSystem.ActionManager
|
||||||
|
import com.intellij.openapi.actionSystem.IdeActions
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.command.CommandProcessor
|
||||||
|
import com.intellij.openapi.command.UndoConfirmationPolicy
|
||||||
|
import com.intellij.openapi.editor.Document
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
|
||||||
|
import com.intellij.openapi.fileEditor.TextEditor
|
||||||
|
import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx
|
||||||
|
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.ui.playback.commands.ActionCommand
|
||||||
|
import org.acejump.search.Tag
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for actions available after typing a tag.
|
||||||
|
*/
|
||||||
|
sealed class AceTagAction {
|
||||||
|
abstract operator fun invoke(tag: Tag, shiftMode: Boolean, isFinal: Boolean)
|
||||||
|
|
||||||
|
abstract class BaseJumpAction : AceTagAction() {
|
||||||
|
override fun invoke(tag: Tag, shiftMode: Boolean, isFinal: Boolean) {
|
||||||
|
val editor = tag.editor
|
||||||
|
val caretModel = editor.caretModel
|
||||||
|
val oldCarets = if (shiftMode) caretModel.caretsAndSelections else emptyList()
|
||||||
|
|
||||||
|
editor.project?.let { addCurrentPositionToHistory(it, editor.document) }
|
||||||
|
|
||||||
|
if (isFinal) {
|
||||||
|
ensureEditorFocused(editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
moveCaretTo(editor, tag.offset)
|
||||||
|
|
||||||
|
if (shiftMode) {
|
||||||
|
caretModel.caretsAndSelections = oldCarets + caretModel.caretsAndSelections
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
fun moveCaretTo(editor: Editor, offset: Int) = with(editor) {
|
||||||
|
selectionModel.removeSelection(true)
|
||||||
|
caretModel.removeSecondaryCarets()
|
||||||
|
caretModel.moveToOffset(offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun performAction(actionName: String) {
|
||||||
|
val actionManager = ActionManager.getInstance()
|
||||||
|
val action = actionManager.getAction(actionName)
|
||||||
|
if (action != null) {
|
||||||
|
actionManager.tryToExecute(action, ActionCommand.getInputEvent(null), null, null, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ensureEditorFocused(editor: Editor) {
|
||||||
|
val project = editor.project ?: return
|
||||||
|
val fem = FileEditorManagerEx.getInstanceEx(project)
|
||||||
|
|
||||||
|
val window = fem.windows.firstOrNull { (it.selectedComposite?.selectedWithProvider?.fileEditor as? TextEditor)?.editor === editor }
|
||||||
|
if (window != null && window !== fem.currentWindow) {
|
||||||
|
fem.currentWindow = window
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addCurrentPositionToHistory(project: Project, document: Document) {
|
||||||
|
CommandProcessor.getInstance().executeCommand(project, {
|
||||||
|
with(IdeDocumentHistory.getInstance(project)) {
|
||||||
|
setCurrentCommandHasMoves()
|
||||||
|
includeCurrentCommandAsNavigation()
|
||||||
|
includeCurrentPlaceAsChangePlace()
|
||||||
|
}
|
||||||
|
}, "AceJumpHistoryAppender", DocCommandGroupId.noneGroupId(document), UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION, document)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On default action, places the caret at the first character of the search query.
|
||||||
|
* On shift action, adds the new caret to existing carets.
|
||||||
|
*/
|
||||||
|
object JumpToSearchStart : BaseJumpAction()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* On default action, performs the Go To Declaration action, available via `Navigate | Declaration or Usages`.
|
||||||
|
* On shift action, performs the Go To Type Declaration action, available via `Navigate | Type Declaration`.
|
||||||
|
* Always places the caret at the start of the word.
|
||||||
|
*/
|
||||||
|
object GoToDeclaration : AceTagAction() {
|
||||||
|
override fun invoke(tag: Tag, shiftMode: Boolean, isFinal: Boolean) {
|
||||||
|
JumpToSearchStart.invoke(tag, shiftMode = false, isFinal = isFinal)
|
||||||
|
ApplicationManager.getApplication().invokeLater { performAction(if (shiftMode) IdeActions.ACTION_GOTO_TYPE_DECLARATION else IdeActions.ACTION_GOTO_DECLARATION) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
185
src/main/kotlin/org/acejump/action/AceVimAction.kt
Normal file
185
src/main/kotlin/org/acejump/action/AceVimAction.kt
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
package org.acejump.action
|
||||||
|
|
||||||
|
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||||
|
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||||
|
import com.intellij.openapi.application.ApplicationManager
|
||||||
|
import com.intellij.openapi.application.WriteAction
|
||||||
|
import com.intellij.openapi.project.DumbAwareAction
|
||||||
|
import com.maddyhome.idea.vim.KeyHandler
|
||||||
|
import com.maddyhome.idea.vim.action.change.change.ChangeVisualAction
|
||||||
|
import com.maddyhome.idea.vim.action.change.delete.DeleteVisualAction
|
||||||
|
import com.maddyhome.idea.vim.action.copy.YankVisualAction
|
||||||
|
import com.maddyhome.idea.vim.api.injector
|
||||||
|
import com.maddyhome.idea.vim.command.MappingMode.OP_PENDING
|
||||||
|
import com.maddyhome.idea.vim.command.OperatorArguments
|
||||||
|
import com.maddyhome.idea.vim.group.visual.vimSetSelection
|
||||||
|
import com.maddyhome.idea.vim.helper.inVisualMode
|
||||||
|
import com.maddyhome.idea.vim.helper.vimSelectionStart
|
||||||
|
import com.maddyhome.idea.vim.helper.vimStateMachine
|
||||||
|
import com.maddyhome.idea.vim.newapi.vim
|
||||||
|
import com.maddyhome.idea.vim.state.mode.SelectionType
|
||||||
|
import org.acejump.boundaries.StandardBoundaries.AFTER_CARET
|
||||||
|
import org.acejump.boundaries.StandardBoundaries.BEFORE_CARET
|
||||||
|
import org.acejump.boundaries.StandardBoundaries.CARET_LINE
|
||||||
|
import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
|
||||||
|
import org.acejump.modes.JumpMode
|
||||||
|
import org.acejump.search.Pattern
|
||||||
|
import org.acejump.search.Tag
|
||||||
|
import org.acejump.session.SessionManager
|
||||||
|
import org.acejump.session.SessionState
|
||||||
|
|
||||||
|
sealed class AceVimAction : DumbAwareAction() {
|
||||||
|
protected abstract val mode: AceVimMode
|
||||||
|
|
||||||
|
final override fun actionPerformed(e: AnActionEvent) {
|
||||||
|
val editor = e.getData(CommonDataKeys.EDITOR) ?: return
|
||||||
|
val context = e.dataContext.vim
|
||||||
|
|
||||||
|
val caret = editor.caretModel.currentCaret
|
||||||
|
val initialOffset = caret.offset
|
||||||
|
val selectionStart = if (editor.inVisualMode) caret.vimSelectionStart else null
|
||||||
|
|
||||||
|
val session = SessionManager.start(editor, mode.getJumpEditors(editor))
|
||||||
|
|
||||||
|
session.defaultBoundary = mode.boundaries
|
||||||
|
session.startJumpMode {
|
||||||
|
object : JumpMode() {
|
||||||
|
override fun accept(state: SessionState, acceptedTag: Tag) {
|
||||||
|
AceTagAction.JumpToSearchStart.invoke(acceptedTag, shiftMode = wasUpperCase, isFinal = true)
|
||||||
|
|
||||||
|
if (selectionStart != null) {
|
||||||
|
caret.vim.vimSetSelection(selectionStart, caret.offset, moveCaretToSelectionEnd = true)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
val vim = editor.vim
|
||||||
|
val commandState = vim.vimStateMachine
|
||||||
|
if (commandState.isOperatorPending) {
|
||||||
|
val key = commandState.commandBuilder.keys.singleOrNull()?.keyChar
|
||||||
|
|
||||||
|
commandState.reset()
|
||||||
|
KeyHandler.getInstance().fullReset(vim)
|
||||||
|
|
||||||
|
AceVimUtil.enterVisualMode(vim, SelectionType.CHARACTER_WISE)
|
||||||
|
caret.vim.vimSetSelection(caret.offset, initialOffset, moveCaretToSelectionEnd = true)
|
||||||
|
|
||||||
|
val action = when (key) {
|
||||||
|
'd' -> DeleteVisualAction()
|
||||||
|
'c' -> ChangeVisualAction()
|
||||||
|
'y' -> YankVisualAction()
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action != null) {
|
||||||
|
ApplicationManager.getApplication().invokeLater {
|
||||||
|
WriteAction.run<Nothing> {
|
||||||
|
commandState.commandBuilder.pushCommandPart(action)
|
||||||
|
|
||||||
|
val cmd = commandState.commandBuilder.buildCommand()
|
||||||
|
val operatorArguments = OperatorArguments(commandState.mappingState.mappingMode == OP_PENDING, cmd.rawCount, commandState.mode)
|
||||||
|
|
||||||
|
commandState.executingCommand = cmd
|
||||||
|
injector.actionExecutor.executeVimAction(vim, action, context, operatorArguments)
|
||||||
|
// TODO does not update status
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
injector.scroll.scrollCaretIntoView(editor.vim)
|
||||||
|
mode.finishSession(editor, session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mode.setupSession(editor, session)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpAllEditors : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpAllEditors
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.Jump(AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.Jump(BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpTillForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpTillForward(AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpTillBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpTillBackward(BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpOnLineForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.Jump(AFTER_CARET.intersection(CARET_LINE))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpOnLineBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.Jump(BEFORE_CARET.intersection(CARET_LINE))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLineIndentsForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.LINE_INDENTS, AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLineIndentsBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.LINE_INDENTS, BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLWordForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_LWORD, AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpUWordForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_UWORD, AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLWordBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_LWORD, BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpUWordBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_UWORD, BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLWordEndForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_LWORD_END, AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpUWordEndForward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_UWORD_END, AFTER_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpLWordEndBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_LWORD_END, BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpUWordEndBackward : AceVimAction() {
|
||||||
|
override val mode = AceVimMode.JumpToPattern(Pattern.VIM_UWORD_END, BEFORE_CARET.intersection(VISIBLE_ON_SCREEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpAllEditorsGoToDeclaration : DumbAwareAction() {
|
||||||
|
override fun update(action: AnActionEvent) {
|
||||||
|
action.presentation.isEnabled = action.getData(CommonDataKeys.EDITOR) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun actionPerformed(e: AnActionEvent) {
|
||||||
|
val editor = e.getData(CommonDataKeys.EDITOR) ?: return
|
||||||
|
val session = SessionManager.start(editor, AceVimMode.JumpAllEditors.getJumpEditors(editor))
|
||||||
|
|
||||||
|
session.defaultBoundary = VISIBLE_ON_SCREEN
|
||||||
|
session.startJumpMode {
|
||||||
|
object : JumpMode() {
|
||||||
|
override fun accept(state: SessionState, acceptedTag: Tag) {
|
||||||
|
AceTagAction.GoToDeclaration.invoke(acceptedTag, shiftMode = wasUpperCase, isFinal = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
64
src/main/kotlin/org/acejump/action/AceVimMode.kt
Normal file
64
src/main/kotlin/org/acejump/action/AceVimMode.kt
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
package org.acejump.action
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.acejump.boundaries.Boundaries
|
||||||
|
import org.acejump.boundaries.StandardBoundaries
|
||||||
|
import org.acejump.openEditors
|
||||||
|
import org.acejump.search.Pattern
|
||||||
|
import org.acejump.session.Session
|
||||||
|
|
||||||
|
sealed class AceVimMode {
|
||||||
|
abstract val boundaries: Boundaries
|
||||||
|
|
||||||
|
open fun getJumpEditors(mainEditor: Editor): List<Editor> {
|
||||||
|
return listOf(mainEditor)
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun setupSession(editor: Editor, session: Session) {}
|
||||||
|
open fun finishSession(editor: Editor, session: Session) {}
|
||||||
|
|
||||||
|
class Jump(override val boundaries: Boundaries) : AceVimMode()
|
||||||
|
|
||||||
|
object JumpAllEditors : AceVimMode() {
|
||||||
|
override val boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
|
||||||
|
override fun getJumpEditors(mainEditor: Editor): List<Editor> {
|
||||||
|
val project = mainEditor.project ?: return super.getJumpEditors(mainEditor)
|
||||||
|
|
||||||
|
return project.openEditors
|
||||||
|
.sortedBy { if (it === mainEditor) 0 else 1 }
|
||||||
|
.ifEmpty { listOf(mainEditor) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpTillForward(override val boundaries: Boundaries) : AceVimMode() {
|
||||||
|
override fun finishSession(editor: Editor, session: Session) {
|
||||||
|
val document = editor.document
|
||||||
|
|
||||||
|
for (caret in editor.caretModel.allCarets) {
|
||||||
|
val offset = caret.offset
|
||||||
|
if (offset > document.getLineStartOffset(document.getLineNumber(offset))) {
|
||||||
|
caret.moveToOffset(offset - 1, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpTillBackward(override val boundaries: Boundaries) : AceVimMode() {
|
||||||
|
override fun finishSession(editor: Editor, session: Session) {
|
||||||
|
val document = editor.document
|
||||||
|
|
||||||
|
for (caret in editor.caretModel.allCarets) {
|
||||||
|
val offset = caret.offset
|
||||||
|
if (offset < document.getLineEndOffset(document.getLineNumber(offset))) {
|
||||||
|
caret.moveToOffset(offset + 1, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JumpToPattern(private val pattern: Pattern, override val boundaries: Boundaries) : AceVimMode() {
|
||||||
|
override fun setupSession(editor: Editor, session: Session) {
|
||||||
|
session.startRegexSearch(pattern)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
src/main/kotlin/org/acejump/action/AceVimUtil.java
Normal file
13
src/main/kotlin/org/acejump/action/AceVimUtil.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package org.acejump.action;
|
||||||
|
|
||||||
|
import com.maddyhome.idea.vim.VimPlugin;
|
||||||
|
import com.maddyhome.idea.vim.api.VimEditor;
|
||||||
|
import com.maddyhome.idea.vim.state.mode.SelectionType;
|
||||||
|
|
||||||
|
final class AceVimUtil {
|
||||||
|
private AceVimUtil() {}
|
||||||
|
|
||||||
|
public static void enterVisualMode(final VimEditor vim, final SelectionType mode) {
|
||||||
|
VimPlugin.getVisualMotion().enterVisualMode(vim, mode);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,108 +0,0 @@
|
|||||||
package org.acejump.action
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
|
|
||||||
import com.intellij.codeInsight.navigation.actions.GotoTypeDeclarationAction
|
|
||||||
import com.intellij.openapi.actionSystem.ActionManager
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction
|
|
||||||
import com.intellij.openapi.command.CommandProcessor
|
|
||||||
import com.intellij.openapi.command.UndoConfirmationPolicy
|
|
||||||
import com.intellij.openapi.editor.Document
|
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import com.intellij.openapi.editor.actionSystem.DocCommandGroupId
|
|
||||||
import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.openapi.ui.playback.commands.ActionCommand
|
|
||||||
import org.acejump.*
|
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.input.JumpMode.*
|
|
||||||
import org.acejump.search.SearchProcessor
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs [JumpMode] navigation and actions.
|
|
||||||
*/
|
|
||||||
internal class TagJumper(private val editor: Editor, private val mode: JumpMode, private val searchProcessor: SearchProcessor?) {
|
|
||||||
/**
|
|
||||||
* Moves caret to a specific offset in the editor according to the positioning and selection rules of the current [JumpMode].
|
|
||||||
*/
|
|
||||||
fun visit(offset: Int) {
|
|
||||||
if (mode === JUMP_END || mode === TARGET) {
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val matchingChars = searchProcessor?.let { chars.countMatchingCharacters(offset, it.query.rawText) } ?: 0
|
|
||||||
val targetOffset = offset + matchingChars
|
|
||||||
val isInsideWord = matchingChars > 0 && chars[targetOffset - 1].isWordPart && chars[targetOffset].isWordPart
|
|
||||||
val finalTargetOffset = if (isInsideWord) chars.wordEnd(targetOffset) + 1 else targetOffset
|
|
||||||
|
|
||||||
if (mode === JUMP_END) {
|
|
||||||
moveCaretTo(editor, finalTargetOffset)
|
|
||||||
}
|
|
||||||
else if (mode === TARGET) {
|
|
||||||
if (isInsideWord) {
|
|
||||||
selectRange(editor, chars.wordStart(targetOffset), finalTargetOffset)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
selectRange(editor, offset, finalTargetOffset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
moveCaretTo(editor, offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates caret and selection by [visit]ing a specific offset in the editor, and applying session-finalizing [JumpMode] actions such as
|
|
||||||
* using the Go To Declaration action, or selecting text between caret and target offset/word if Shift was held during the jump.
|
|
||||||
*/
|
|
||||||
fun jump(offset: Int, shiftMode: Boolean) {
|
|
||||||
val oldOffset = editor.caretModel.offset
|
|
||||||
|
|
||||||
visit(offset)
|
|
||||||
|
|
||||||
if (mode === DEFINE) {
|
|
||||||
performAction(if (shiftMode) GotoTypeDeclarationAction() else GotoDeclarationAction())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shiftMode) {
|
|
||||||
val newOffset = editor.caretModel.offset
|
|
||||||
|
|
||||||
if (mode === TARGET) {
|
|
||||||
selectRange(editor, oldOffset, when {
|
|
||||||
newOffset < oldOffset -> editor.selectionModel.selectionStart
|
|
||||||
else -> editor.selectionModel.selectionEnd
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
selectRange(editor, oldOffset, newOffset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private companion object {
|
|
||||||
private fun moveCaretTo(editor: Editor, offset: Int) = with(editor) {
|
|
||||||
project?.let { addCurrentPositionToHistory(it, document) }
|
|
||||||
selectionModel.removeSelection(true)
|
|
||||||
caretModel.moveToOffset(offset)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun selectRange(editor: Editor, fromOffset: Int, toOffset: Int) = with(editor) {
|
|
||||||
selectionModel.removeSelection(true)
|
|
||||||
selectionModel.setSelection(fromOffset, toOffset)
|
|
||||||
caretModel.moveToOffset(toOffset)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addCurrentPositionToHistory(project: Project, document: Document) {
|
|
||||||
CommandProcessor.getInstance().executeCommand(project, {
|
|
||||||
with(IdeDocumentHistory.getInstance(project)) {
|
|
||||||
setCurrentCommandHasMoves()
|
|
||||||
includeCurrentCommandAsNavigation()
|
|
||||||
includeCurrentPlaceAsChangePlace()
|
|
||||||
}
|
|
||||||
}, "AceJumpHistoryAppender", DocCommandGroupId.noneGroupId(document), UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION, document)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun performAction(action: AnAction) {
|
|
||||||
ActionManager.getInstance().tryToExecute(action, ActionCommand.getInputEvent(null), null, null, true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,73 +0,0 @@
|
|||||||
package org.acejump.action
|
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import com.intellij.openapi.editor.ScrollType
|
|
||||||
import com.intellij.openapi.editor.SelectionModel
|
|
||||||
import org.acejump.search.SearchProcessor
|
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enables navigation between currently active tags.
|
|
||||||
*/
|
|
||||||
internal class TagVisitor(private val editor: Editor, private val searchProcessor: SearchProcessor, private val tagJumper: TagJumper) {
|
|
||||||
/**
|
|
||||||
* Places caret at the closest tag following the caret position, according to the rules of the current jump mode (see [TagJumper.visit]).
|
|
||||||
* If the caret is at or past the last tag, it moves to the first tag instead.
|
|
||||||
* If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
|
|
||||||
*/
|
|
||||||
fun visitNext(): Boolean {
|
|
||||||
return visit(SelectionModel::getSelectionEnd) { if (it < 0) -it - 1 else it + 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Places caret at the closest tag preceding the caret position, according to the rules of the current jump mode (see [TagJumper.visit]).
|
|
||||||
* If the caret is at or before the first tag, it moves to the last tag instead.
|
|
||||||
* If there is only one tag, it immediately performs the jump action as described in [TagJumper.jump].
|
|
||||||
*/
|
|
||||||
fun visitPrevious(): Boolean {
|
|
||||||
return visit(SelectionModel::getSelectionStart) { if (it < 0) -it - 2 else it - 1 }
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scrolls to the closest result to the caret.
|
|
||||||
*/
|
|
||||||
fun scrollToClosest() {
|
|
||||||
val caret = editor.caretModel.offset
|
|
||||||
val results = searchProcessor.results.takeUnless { it.isEmpty } ?: return
|
|
||||||
val index = results.binarySearch(caret).let { if (it < 0) -it - 1 else it }
|
|
||||||
|
|
||||||
val targetOffset = listOfNotNull(
|
|
||||||
results.getOrNull(index - 1),
|
|
||||||
results.getOrNull(index)
|
|
||||||
).minBy {
|
|
||||||
abs(it - caret)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetOffset != null) {
|
|
||||||
editor.scrollingModel.scrollTo(editor.offsetToLogicalPosition(targetOffset), ScrollType.RELATIVE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun visit(caretPosition: SelectionModel.() -> Int, indexModifier: (Int) -> Int): Boolean {
|
|
||||||
val results = searchProcessor.results.takeUnless { it.isEmpty } ?: return false
|
|
||||||
val nextIndex = indexModifier(results.binarySearch(caretPosition(editor.selectionModel)))
|
|
||||||
|
|
||||||
val targetOffset = results.getInt(when {
|
|
||||||
nextIndex < 0 -> results.lastIndex
|
|
||||||
nextIndex > results.lastIndex -> 0
|
|
||||||
else -> nextIndex
|
|
||||||
})
|
|
||||||
|
|
||||||
val onlyResult = results.size == 1
|
|
||||||
|
|
||||||
if (onlyResult) {
|
|
||||||
tagJumper.jump(targetOffset, shiftMode = false)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
tagJumper.visit(targetOffset)
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.scrollingModel.scrollToCaret(ScrollType.RELATIVE)
|
|
||||||
return onlyResult
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,16 +3,6 @@ package org.acejump.boundaries
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
|
|
||||||
enum class StandardBoundaries : Boundaries {
|
enum class StandardBoundaries : Boundaries {
|
||||||
WHOLE_FILE {
|
|
||||||
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
|
||||||
return 0 until editor.document.textLength
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
|
||||||
return offset in (0 until editor.document.textLength)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
VISIBLE_ON_SCREEN {
|
VISIBLE_ON_SCREEN {
|
||||||
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
||||||
val (topLeft, bottomRight) = cache.visibleArea(editor)
|
val (topLeft, bottomRight) = cache.visibleArea(editor)
|
||||||
@@ -45,21 +35,34 @@ enum class StandardBoundaries : Boundaries {
|
|||||||
|
|
||||||
BEFORE_CARET {
|
BEFORE_CARET {
|
||||||
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
||||||
return 0..(editor.caretModel.offset)
|
return 0 until editor.caretModel.offset
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
||||||
return offset <= editor.caretModel.offset
|
return offset < editor.caretModel.offset
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
AFTER_CARET {
|
AFTER_CARET {
|
||||||
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
||||||
return editor.caretModel.offset until editor.document.textLength
|
return (editor.caretModel.offset + 1) until editor.document.textLength
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
||||||
return offset >= editor.caretModel.offset
|
return offset > editor.caretModel.offset
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
CARET_LINE {
|
||||||
|
override fun getOffsetRange(editor: Editor, cache: EditorOffsetCache): IntRange {
|
||||||
|
val document = editor.document
|
||||||
|
val offset = editor.caretModel.offset
|
||||||
|
val line = document.getLineNumber(offset)
|
||||||
|
return document.getLineStartOffset(line)..document.getLineEndOffset(line)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isOffsetInside(editor: Editor, offset: Int, cache: EditorOffsetCache): Boolean {
|
||||||
|
return offset in getOffsetRange(editor, cache)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -19,16 +19,10 @@ class AceConfig : PersistentStateComponent<AceSettings> {
|
|||||||
get() = ServiceManager.getService(AceConfig::class.java).aceSettings
|
get() = ServiceManager.getService(AceConfig::class.java).aceSettings
|
||||||
|
|
||||||
val layout get() = settings.layout
|
val layout get() = settings.layout
|
||||||
val cycleModes get() = settings.let { arrayOf(it.cycleMode1, it.cycleMode2, it.cycleMode3, it.cycleMode4) }
|
|
||||||
val minQueryLength get() = settings.minQueryLength
|
val minQueryLength get() = settings.minQueryLength
|
||||||
val jumpModeColor get() = settings.jumpModeColor
|
val jumpModeColor get() = settings.jumpModeColor
|
||||||
val jumpEndModeColor get() = settings.jumpEndModeColor
|
|
||||||
val targetModeColor get() = settings.targetModeColor
|
|
||||||
val definitionModeColor get() = settings.definitionModeColor
|
|
||||||
val textHighlightColor get() = settings.textHighlightColor
|
|
||||||
val tagForegroundColor get() = settings.tagForegroundColor
|
val tagForegroundColor get() = settings.tagForegroundColor
|
||||||
val tagBackgroundColor get() = settings.tagBackgroundColor
|
val searchHighlightColor get() = settings.searchHighlightColor
|
||||||
val searchWholeFile get() = settings.searchWholeFile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getState(): AceSettings {
|
override fun getState(): AceSettings {
|
||||||
|
@@ -13,37 +13,21 @@ class AceConfigurable : Configurable {
|
|||||||
|
|
||||||
override fun isModified() =
|
override fun isModified() =
|
||||||
panel.allowedChars != settings.allowedChars ||
|
panel.allowedChars != settings.allowedChars ||
|
||||||
|
panel.prefixChars != settings.prefixChars ||
|
||||||
panel.keyboardLayout != settings.layout ||
|
panel.keyboardLayout != settings.layout ||
|
||||||
panel.cycleMode1 != settings.cycleMode1 ||
|
|
||||||
panel.cycleMode2 != settings.cycleMode2 ||
|
|
||||||
panel.cycleMode3 != settings.cycleMode3 ||
|
|
||||||
panel.cycleMode4 != settings.cycleMode4 ||
|
|
||||||
panel.minQueryLengthInt != settings.minQueryLength ||
|
panel.minQueryLengthInt != settings.minQueryLength ||
|
||||||
panel.jumpModeColor != settings.jumpModeColor ||
|
panel.jumpModeColor != settings.jumpModeColor ||
|
||||||
panel.jumpEndModeColor != settings.jumpEndModeColor ||
|
|
||||||
panel.targetModeColor != settings.targetModeColor ||
|
|
||||||
panel.definitionModeColor != settings.definitionModeColor ||
|
|
||||||
panel.textHighlightColor != settings.textHighlightColor ||
|
|
||||||
panel.tagForegroundColor != settings.tagForegroundColor ||
|
panel.tagForegroundColor != settings.tagForegroundColor ||
|
||||||
panel.tagBackgroundColor != settings.tagBackgroundColor ||
|
panel.searchHighlightColor != settings.searchHighlightColor
|
||||||
panel.searchWholeFile != settings.searchWholeFile
|
|
||||||
|
|
||||||
override fun apply() {
|
override fun apply() {
|
||||||
settings.allowedChars = panel.allowedChars
|
settings.allowedChars = panel.allowedChars
|
||||||
|
settings.prefixChars = panel.prefixChars
|
||||||
settings.layout = panel.keyboardLayout
|
settings.layout = panel.keyboardLayout
|
||||||
settings.cycleMode1 = panel.cycleMode1
|
|
||||||
settings.cycleMode2 = panel.cycleMode2
|
|
||||||
settings.cycleMode3 = panel.cycleMode3
|
|
||||||
settings.cycleMode4 = panel.cycleMode4
|
|
||||||
settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength
|
settings.minQueryLength = panel.minQueryLengthInt ?: settings.minQueryLength
|
||||||
panel.jumpModeColor?.let { settings.jumpModeColor = it }
|
panel.jumpModeColor?.let { settings.jumpModeColor = it }
|
||||||
panel.jumpEndModeColor?.let { settings.jumpEndModeColor = it }
|
|
||||||
panel.targetModeColor?.let { settings.targetModeColor = it }
|
|
||||||
panel.definitionModeColor?.let { settings.definitionModeColor = it }
|
|
||||||
panel.textHighlightColor?.let { settings.textHighlightColor = it }
|
|
||||||
panel.tagForegroundColor?.let { settings.tagForegroundColor = it }
|
panel.tagForegroundColor?.let { settings.tagForegroundColor = it }
|
||||||
panel.tagBackgroundColor?.let { settings.tagBackgroundColor = it }
|
panel.searchHighlightColor?.let { settings.searchHighlightColor = it }
|
||||||
settings.searchWholeFile = panel.searchWholeFile
|
|
||||||
KeyLayoutCache.reset(settings)
|
KeyLayoutCache.reset(settings)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package org.acejump.config
|
package org.acejump.config
|
||||||
|
|
||||||
import com.intellij.util.xmlb.annotations.OptionTag
|
import com.intellij.util.xmlb.annotations.OptionTag
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.input.KeyLayout
|
import org.acejump.input.KeyLayout
|
||||||
import org.acejump.input.KeyLayout.QWERTY
|
import org.acejump.input.KeyLayout.QWERTY
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
@@ -9,32 +8,15 @@ import java.awt.Color
|
|||||||
data class AceSettings(
|
data class AceSettings(
|
||||||
var layout: KeyLayout = QWERTY,
|
var layout: KeyLayout = QWERTY,
|
||||||
var allowedChars: String = layout.allChars,
|
var allowedChars: String = layout.allChars,
|
||||||
var cycleMode1: JumpMode = JumpMode.JUMP,
|
var prefixChars: String = ";",
|
||||||
var cycleMode2: JumpMode = JumpMode.DEFINE,
|
|
||||||
var cycleMode3: JumpMode = JumpMode.TARGET,
|
|
||||||
var cycleMode4: JumpMode = JumpMode.JUMP_END,
|
|
||||||
var minQueryLength: Int = 1,
|
var minQueryLength: Int = 1,
|
||||||
|
|
||||||
@OptionTag("jumpModeRGB", converter = ColorConverter::class)
|
@OptionTag("jumpModeRGB", converter = ColorConverter::class)
|
||||||
var jumpModeColor: Color = Color(0xFFFFFF),
|
var jumpModeColor: Color = Color(0xFFFFFF),
|
||||||
|
|
||||||
@OptionTag("jumpEndModeRGB", converter = ColorConverter::class)
|
|
||||||
var jumpEndModeColor: Color = Color(0x33E78A),
|
|
||||||
|
|
||||||
@OptionTag("targetModeRGB", converter = ColorConverter::class)
|
|
||||||
var targetModeColor: Color = Color(0xFFB700),
|
|
||||||
|
|
||||||
@OptionTag("definitionModeRGB", converter = ColorConverter::class)
|
|
||||||
var definitionModeColor: Color = Color(0x6FC5FF),
|
|
||||||
|
|
||||||
@OptionTag("textHighlightRGB", converter = ColorConverter::class)
|
|
||||||
var textHighlightColor: Color = Color(0x394B58),
|
|
||||||
|
|
||||||
@OptionTag("tagForegroundRGB", converter = ColorConverter::class)
|
@OptionTag("tagForegroundRGB", converter = ColorConverter::class)
|
||||||
var tagForegroundColor: Color = Color(0xFFFFFF),
|
var tagForegroundColor: Color = Color(0xFFFFFF),
|
||||||
|
|
||||||
@OptionTag("tagBackgroundRGB", converter = ColorConverter::class)
|
@OptionTag("searchHighlightRGB", converter = ColorConverter::class)
|
||||||
var tagBackgroundColor: Color = Color(0x008299),
|
var searchHighlightColor: Color = Color(0x008299),
|
||||||
|
|
||||||
var searchWholeFile: Boolean = true
|
|
||||||
)
|
)
|
||||||
|
@@ -2,14 +2,12 @@ package org.acejump.config
|
|||||||
|
|
||||||
import com.intellij.openapi.ui.ComboBox
|
import com.intellij.openapi.ui.ComboBox
|
||||||
import com.intellij.ui.ColorPanel
|
import com.intellij.ui.ColorPanel
|
||||||
import com.intellij.ui.components.JBCheckBox
|
|
||||||
import com.intellij.ui.components.JBTextArea
|
import com.intellij.ui.components.JBTextArea
|
||||||
import com.intellij.ui.components.JBTextField
|
import com.intellij.ui.components.JBTextField
|
||||||
import com.intellij.ui.layout.Cell
|
import com.intellij.ui.layout.Cell
|
||||||
import com.intellij.ui.layout.GrowPolicy.MEDIUM_TEXT
|
import com.intellij.ui.layout.GrowPolicy.MEDIUM_TEXT
|
||||||
import com.intellij.ui.layout.GrowPolicy.SHORT_TEXT
|
import com.intellij.ui.layout.GrowPolicy.SHORT_TEXT
|
||||||
import com.intellij.ui.layout.panel
|
import com.intellij.ui.layout.panel
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.input.KeyLayout
|
import org.acejump.input.KeyLayout
|
||||||
import java.awt.Color
|
import java.awt.Color
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
@@ -24,31 +22,20 @@ import kotlin.reflect.KProperty
|
|||||||
*/
|
*/
|
||||||
@Suppress("UsePropertyAccessSyntax")
|
@Suppress("UsePropertyAccessSyntax")
|
||||||
internal class AceSettingsPanel {
|
internal class AceSettingsPanel {
|
||||||
private val tagCharsField = JBTextField()
|
private val tagAllowedCharsField = JBTextField()
|
||||||
|
private val tagPrefixCharsField = JBTextField()
|
||||||
private val keyboardLayoutCombo = ComboBox<KeyLayout>()
|
private val keyboardLayoutCombo = ComboBox<KeyLayout>()
|
||||||
private val keyboardLayoutArea = JBTextArea().apply { isEditable = false }
|
private val keyboardLayoutArea = JBTextArea().apply { isEditable = false }
|
||||||
private val cycleModeCombo1 = ComboBox<JumpMode>()
|
|
||||||
private val cycleModeCombo2 = ComboBox<JumpMode>()
|
|
||||||
private val cycleModeCombo3 = ComboBox<JumpMode>()
|
|
||||||
private val cycleModeCombo4 = ComboBox<JumpMode>()
|
|
||||||
private val minQueryLengthField = JBTextField()
|
private val minQueryLengthField = JBTextField()
|
||||||
private val jumpModeColorWheel = ColorPanel()
|
private val jumpModeColorWheel = ColorPanel()
|
||||||
private val jumpEndModeColorWheel = ColorPanel()
|
|
||||||
private val targetModeColorWheel = ColorPanel()
|
|
||||||
private val definitionModeColorWheel = ColorPanel()
|
|
||||||
private val textHighlightColorWheel = ColorPanel()
|
|
||||||
private val tagForegroundColorWheel = ColorPanel()
|
private val tagForegroundColorWheel = ColorPanel()
|
||||||
private val tagBackgroundColorWheel = ColorPanel()
|
private val searchHighlightColorWheel = ColorPanel()
|
||||||
private val searchWholeFileCheckBox = JBCheckBox()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
tagCharsField.apply { font = Font("monospaced", font.style, font.size) }
|
tagAllowedCharsField.apply { font = Font("monospaced", font.style, font.size) }
|
||||||
|
tagPrefixCharsField.apply { font = Font("monospaced", font.style, font.size) }
|
||||||
keyboardLayoutArea.apply { font = Font("monospaced", font.style, font.size) }
|
keyboardLayoutArea.apply { font = Font("monospaced", font.style, font.size) }
|
||||||
keyboardLayoutCombo.setupEnumItems { keyChars = it.rows.joinToString("\n") }
|
keyboardLayoutCombo.setupEnumItems { keyChars = it.rows.joinToString("\n") }
|
||||||
cycleModeCombo1.setupEnumItems { cycleMode1 = it }
|
|
||||||
cycleModeCombo2.setupEnumItems { cycleMode2 = it }
|
|
||||||
cycleModeCombo3.setupEnumItems { cycleMode3 = it }
|
|
||||||
cycleModeCombo4.setupEnumItems { cycleMode4 = it }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal val rootPanel: JPanel = panel {
|
internal val rootPanel: JPanel = panel {
|
||||||
@@ -56,55 +43,32 @@ internal class AceSettingsPanel {
|
|||||||
fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
|
fun Cell.medium(component: JComponent) = component(growPolicy = MEDIUM_TEXT)
|
||||||
|
|
||||||
titledRow("Characters and Layout") {
|
titledRow("Characters and Layout") {
|
||||||
row("Allowed characters in tags:") { medium(tagCharsField) }
|
row("Allowed characters in tags:") { medium(tagAllowedCharsField) }
|
||||||
|
row("Allowed prefix characters in tags:") { medium(tagPrefixCharsField) }
|
||||||
row("Keyboard layout:") { short(keyboardLayoutCombo) }
|
row("Keyboard layout:") { short(keyboardLayoutCombo) }
|
||||||
row("Keyboard design:") { short(keyboardLayoutArea) }
|
row("Keyboard design:") { short(keyboardLayoutArea) }
|
||||||
}
|
}
|
||||||
|
|
||||||
titledRow("Modes") {
|
titledRow("Behavior") {
|
||||||
row("Cycle order:") {
|
row("Minimum typed characters (1-10):") { short(minQueryLengthField) }
|
||||||
cell(isVerticalFlow = false, isFullWidth = false) {
|
|
||||||
cycleModeCombo1()
|
|
||||||
cycleModeCombo2()
|
|
||||||
cycleModeCombo3()
|
|
||||||
cycleModeCombo4()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
titledRow("Colors") {
|
titledRow("Colors") {
|
||||||
row("Jump mode caret background:") { short(jumpModeColorWheel) }
|
row("Caret background:") { short(jumpModeColorWheel) }
|
||||||
row("Jump to End mode caret background:") { short(jumpEndModeColorWheel) }
|
|
||||||
row("Target mode caret background:") { short(targetModeColorWheel) }
|
|
||||||
row("Definition mode caret background:") { short(definitionModeColorWheel) }
|
|
||||||
row("Searched text background:") { short(textHighlightColorWheel) }
|
|
||||||
row("Tag foreground:") { short(tagForegroundColorWheel) }
|
row("Tag foreground:") { short(tagForegroundColorWheel) }
|
||||||
row("Tag background:") { short(tagBackgroundColorWheel) }
|
row("Search highlight:") { short(searchHighlightColorWheel) }
|
||||||
}
|
|
||||||
|
|
||||||
titledRow("Behavior") {
|
|
||||||
row { short(searchWholeFileCheckBox.apply { text = "Search whole file" }) }
|
|
||||||
row("Minimum typed characters (1-10):") { short(minQueryLengthField) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Property-to-property delegation: https://stackoverflow.com/q/45074596/1772342
|
// Property-to-property delegation: https://stackoverflow.com/q/45074596/1772342
|
||||||
internal var allowedChars by tagCharsField
|
internal var allowedChars by tagAllowedCharsField
|
||||||
|
internal var prefixChars by tagPrefixCharsField
|
||||||
internal var keyboardLayout by keyboardLayoutCombo
|
internal var keyboardLayout by keyboardLayoutCombo
|
||||||
internal var keyChars by keyboardLayoutArea
|
internal var keyChars by keyboardLayoutArea
|
||||||
internal var cycleMode1 by cycleModeCombo1
|
|
||||||
internal var cycleMode2 by cycleModeCombo2
|
|
||||||
internal var cycleMode3 by cycleModeCombo3
|
|
||||||
internal var cycleMode4 by cycleModeCombo4
|
|
||||||
internal var minQueryLength by minQueryLengthField
|
internal var minQueryLength by minQueryLengthField
|
||||||
internal var jumpModeColor by jumpModeColorWheel
|
internal var jumpModeColor by jumpModeColorWheel
|
||||||
internal var jumpEndModeColor by jumpEndModeColorWheel
|
|
||||||
internal var targetModeColor by targetModeColorWheel
|
|
||||||
internal var definitionModeColor by definitionModeColorWheel
|
|
||||||
internal var textHighlightColor by textHighlightColorWheel
|
|
||||||
internal var tagForegroundColor by tagForegroundColorWheel
|
internal var tagForegroundColor by tagForegroundColorWheel
|
||||||
internal var tagBackgroundColor by tagBackgroundColorWheel
|
internal var searchHighlightColor by searchHighlightColorWheel
|
||||||
internal var searchWholeFile by searchWholeFileCheckBox
|
|
||||||
|
|
||||||
internal var minQueryLengthInt
|
internal var minQueryLengthInt
|
||||||
get() = minQueryLength.toIntOrNull()?.coerceIn(1, 10)
|
get() = minQueryLength.toIntOrNull()?.coerceIn(1, 10)
|
||||||
@@ -112,20 +76,12 @@ internal class AceSettingsPanel {
|
|||||||
|
|
||||||
fun reset(settings: AceSettings) {
|
fun reset(settings: AceSettings) {
|
||||||
allowedChars = settings.allowedChars
|
allowedChars = settings.allowedChars
|
||||||
|
prefixChars = settings.prefixChars
|
||||||
keyboardLayout = settings.layout
|
keyboardLayout = settings.layout
|
||||||
cycleMode1 = settings.cycleMode1
|
|
||||||
cycleMode2 = settings.cycleMode2
|
|
||||||
cycleMode3 = settings.cycleMode3
|
|
||||||
cycleMode4 = settings.cycleMode4
|
|
||||||
minQueryLength = settings.minQueryLength.toString()
|
minQueryLength = settings.minQueryLength.toString()
|
||||||
jumpModeColor = settings.jumpModeColor
|
jumpModeColor = settings.jumpModeColor
|
||||||
jumpEndModeColor = settings.jumpEndModeColor
|
|
||||||
targetModeColor = settings.targetModeColor
|
|
||||||
definitionModeColor = settings.definitionModeColor
|
|
||||||
textHighlightColor = settings.textHighlightColor
|
|
||||||
tagForegroundColor = settings.tagForegroundColor
|
tagForegroundColor = settings.tagForegroundColor
|
||||||
tagBackgroundColor = settings.tagBackgroundColor
|
searchHighlightColor = settings.searchHighlightColor
|
||||||
searchWholeFile = settings.searchWholeFile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removal pending support for https://youtrack.jetbrains.com/issue/KT-8575
|
// Removal pending support for https://youtrack.jetbrains.com/issue/KT-8575
|
||||||
|
@@ -1,68 +0,0 @@
|
|||||||
package org.acejump.input
|
|
||||||
|
|
||||||
import com.intellij.openapi.editor.colors.impl.AbstractColorsScheme
|
|
||||||
import org.acejump.config.AceConfig
|
|
||||||
import java.awt.Color
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes modes that determine the behavior of a "jump" to a tag. Most modes have two variations:
|
|
||||||
* - **Default jump** happens when jumping without holding the Shift key
|
|
||||||
* - **Shift jump** happens when jumping while holding the Shift key
|
|
||||||
*/
|
|
||||||
enum class JumpMode {
|
|
||||||
/**
|
|
||||||
* Default value at the start of a session. If the session does not get assigned a proper [JumpMode] by the time the user requests a jump,
|
|
||||||
* the results of the jump are undefined.
|
|
||||||
*/
|
|
||||||
DISABLED,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On default jump, places the caret at the first character of the search query.
|
|
||||||
* On shift jump, does the above but also selects all text between the original and new caret positions.
|
|
||||||
*/
|
|
||||||
JUMP,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On default jump, places the caret at the end of a word. Word detection uses [Character.isJavaIdentifierPart] to count some special
|
|
||||||
* characters, such as underscores, as part of a word. If there is no word at the first character of the search query, then the caret is
|
|
||||||
* placed after the last character of the search query.
|
|
||||||
*
|
|
||||||
* On shift jump, does the above but also selects all text between the original and new caret positions.
|
|
||||||
*/
|
|
||||||
JUMP_END,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On default jump, places the caret at the end of a word, and also selects the entire word. Word detection uses
|
|
||||||
* [Character.isJavaIdentifierPart] to count some special characters, such as underscores, as part of a word. If there is no word at the
|
|
||||||
* first character of the search query, then the caret is placed after the last character of the search query, and all text between the
|
|
||||||
* start and end of the search query is selected.
|
|
||||||
*
|
|
||||||
* On shift jump, does the above but also selects all text between the original caret position and the new selection, merging the
|
|
||||||
* selections into one.
|
|
||||||
*/
|
|
||||||
TARGET,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* On default jump, performs the Go To Declaration action, available via `Navigate | Declaration or Usages`.
|
|
||||||
* On shift jump, performs the Go To Type Declaration action, available via `Navigate | Type Declaration`.
|
|
||||||
* Always places the caret at the first character of the search query.
|
|
||||||
*/
|
|
||||||
DEFINE;
|
|
||||||
|
|
||||||
val caretColor: Color
|
|
||||||
get() = when (this) {
|
|
||||||
JUMP -> AceConfig.jumpModeColor
|
|
||||||
JUMP_END -> AceConfig.jumpEndModeColor
|
|
||||||
DEFINE -> AceConfig.definitionModeColor
|
|
||||||
TARGET -> AceConfig.targetModeColor
|
|
||||||
DISABLED -> AbstractColorsScheme.INHERITED_COLOR_MARKER
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString() = when (this) {
|
|
||||||
DISABLED -> "(Skip)"
|
|
||||||
JUMP -> "Jump"
|
|
||||||
JUMP_END -> "Jump to End"
|
|
||||||
TARGET -> "Target"
|
|
||||||
DEFINE -> "Definition"
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,53 +0,0 @@
|
|||||||
package org.acejump.input
|
|
||||||
|
|
||||||
import org.acejump.config.AceConfig
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remembers the current [JumpMode] for a session. Allows cycling [JumpMode]s according to the order defined in configuration, or toggling
|
|
||||||
* one specific [JumpMode] on or off.
|
|
||||||
*/
|
|
||||||
internal class JumpModeTracker {
|
|
||||||
private var currentMode = JumpMode.DISABLED
|
|
||||||
private var currentIndex = 0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switches to the next/previous [JumpMode] defined in configuration, skipping any [JumpMode]s that are not assigned. If at least two
|
|
||||||
* [JumpMode]s are assigned in the cycle order, then cycling will wrap around. If only one [JumpMode] is assigned, then cycling will
|
|
||||||
* toggle that one mode.
|
|
||||||
*/
|
|
||||||
fun cycle(forward: Boolean): JumpMode {
|
|
||||||
val cycleModes = AceConfig.cycleModes
|
|
||||||
val direction = if (forward) 1 else -1
|
|
||||||
val start = if (currentIndex == 0 && !forward) 0 else currentIndex - 1
|
|
||||||
|
|
||||||
for (offset in 1 until cycleModes.size) {
|
|
||||||
val index = (start + cycleModes.size + (offset * direction)) % cycleModes.size
|
|
||||||
|
|
||||||
if (cycleModes[index] != JumpMode.DISABLED) {
|
|
||||||
currentMode = cycleModes[index]
|
|
||||||
currentIndex = index + 1
|
|
||||||
return currentMode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentMode = JumpMode.DISABLED
|
|
||||||
currentIndex = 0
|
|
||||||
return currentMode
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switches to the specified [JumpMode]. If the current mode already equals the specified one, it resets to [JumpMode.DISABLED].
|
|
||||||
*/
|
|
||||||
fun toggle(newMode: JumpMode): JumpMode {
|
|
||||||
if (currentMode == newMode) {
|
|
||||||
currentMode = JumpMode.DISABLED
|
|
||||||
currentIndex = 0
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
currentMode = newMode
|
|
||||||
currentIndex = AceConfig.cycleModes.indexOfFirst { it == newMode } + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return currentMode
|
|
||||||
}
|
|
||||||
}
|
|
@@ -7,48 +7,6 @@ import org.acejump.config.AceSettings
|
|||||||
* with repeated keys (ex. FF, JJ) or adjacent keys (ex. GH, UJ).
|
* with repeated keys (ex. FF, JJ) or adjacent keys (ex. GH, UJ).
|
||||||
*/
|
*/
|
||||||
internal object KeyLayoutCache {
|
internal object KeyLayoutCache {
|
||||||
/**
|
|
||||||
* Stores keys ordered by proximity to other keys for the QWERTY layout.
|
|
||||||
* TODO: Support more layouts, perhaps generate automatically.
|
|
||||||
*/
|
|
||||||
private val qwertyCharacterDistances = mapOf(
|
|
||||||
'j' to "jikmnhuolbgypvftcdrxsezawq8796054321",
|
|
||||||
'f' to "ftgvcdryhbxseujnzawqikmolp5463728190",
|
|
||||||
'k' to "kolmjipnhubgyvftcdrxsezawq9807654321",
|
|
||||||
'd' to "drfcxsetgvzawyhbqujnikmolp4352617890",
|
|
||||||
'l' to "lkopmjinhubgyvftcdrxsezawq0987654321",
|
|
||||||
's' to "sedxzawrfcqtgvyhbujnikmolp3241567890",
|
|
||||||
'a' to "aqwszedxrfctgvyhbujnikmolp1234567890",
|
|
||||||
'h' to "hujnbgyikmvftolcdrpxsezawq6758493021",
|
|
||||||
'g' to "gyhbvftujncdrikmxseolzawpq5647382910",
|
|
||||||
'y' to "yuhgtijnbvfrokmcdeplxswzaq6758493021",
|
|
||||||
't' to "tygfruhbvcdeijnxswokmzaqpl5647382910",
|
|
||||||
'u' to "uijhyokmnbgtplvfrcdexswzaq7869504321",
|
|
||||||
'r' to "rtfdeygvcxswuhbzaqijnokmpl4536271890",
|
|
||||||
'n' to "nbhjmvgyuiklocftpxdrzseawq7685940321",
|
|
||||||
'v' to "vcfgbxdrtyhnzseujmawikqolp5463728190",
|
|
||||||
'm' to "mnjkbhuilvgyopcftxdrzseawq8970654321",
|
|
||||||
'c' to "cxdfvzsertgbawyhnqujmikolp4352617890",
|
|
||||||
'b' to "bvghncftyujmxdrikzseolawqp6574839201",
|
|
||||||
'i' to "iokjuplmnhybgtvfrcdexswzaq8970654321",
|
|
||||||
'e' to "erdswtfcxzaqygvuhbijnokmpl3425167890",
|
|
||||||
'x' to "xzsdcawerfvqtgbyhnujmikolp3241567890",
|
|
||||||
'z' to "zasxqwedcrfvtgbyhnujmikolp1234567890",
|
|
||||||
'o' to "oplkimjunhybgtvfrcdexswzaq9087654321",
|
|
||||||
'w' to "wesaqrdxztfcygvuhbijnokmpl2314567890",
|
|
||||||
'p' to "plokimjunhybgtvfrcdexswzaq0987654321",
|
|
||||||
'q' to "qwaeszrdxtfcygvuhbijnokmpl1234567890",
|
|
||||||
'1' to "1234567890qawzsexdrcftvgybhunjimkolp",
|
|
||||||
'2' to "2134567890qwasezxdrcftvgybhunjimkolp",
|
|
||||||
'3' to "3241567890weqasdrzxcftvgybhunjimkolp",
|
|
||||||
'4' to "4352617890erwsdftqazxcvgybhunjimkolp",
|
|
||||||
'5' to "5463728190rtedfgywsxcvbhuqaznjimkolp",
|
|
||||||
'6' to "6574839201tyrfghuedcvbnjiwsxmkoqazlp",
|
|
||||||
'7' to "7685940321yutghjirfvbnmkoedclpwsxqaz",
|
|
||||||
'8' to "8796054321uiyhjkotgbnmlprfvedcwsxqaz",
|
|
||||||
'9' to "9807654321ioujklpyhnmtgbrfvedcwsxqaz",
|
|
||||||
'0' to "0987654321opiklujmyhntgbrfvedcwsxqaz").mapValues { (_, v) -> v.mapIndexed { index, char -> char to index }.toMap() }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts tags according to current keyboard layout settings, and some predefined rules that force tags with digits, and tags with two
|
* Sorts tags according to current keyboard layout settings, and some predefined rules that force tags with digits, and tags with two
|
||||||
* keys far apart, to be sorted after other (easier to type) tags.
|
* keys far apart, to be sorted after other (easier to type) tags.
|
||||||
@@ -59,7 +17,7 @@ internal object KeyLayoutCache {
|
|||||||
/**
|
/**
|
||||||
* Returns all possible two key tags, pre-sorted according to [tagOrder].
|
* Returns all possible two key tags, pre-sorted according to [tagOrder].
|
||||||
*/
|
*/
|
||||||
lateinit var allPossibleTags: List<String>
|
lateinit var allPossibleTagsLowercase: List<String>
|
||||||
private set
|
private set
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,18 +34,20 @@ internal object KeyLayoutCache {
|
|||||||
*/
|
*/
|
||||||
fun reset(settings: AceSettings) {
|
fun reset(settings: AceSettings) {
|
||||||
tagOrder = compareBy(
|
tagOrder = compareBy(
|
||||||
{ it[0].isDigit() || it[1].isDigit() },
|
String::length,
|
||||||
{ qwertyCharacterDistances.getValue(it[0]).getValue(it[1]) },
|
settings.layout.priority(String::last)
|
||||||
settings.layout.priority { it[0] }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val allPossibleChars = settings.allowedChars
|
@Suppress("ConvertLambdaToReference")
|
||||||
.toCharArray()
|
val allSuffixChars = processCharList(settings.allowedChars).ifEmpty { processCharList(settings.layout.allChars).toList() }
|
||||||
.filter(Char::isLetterOrDigit)
|
val allPrefixChars = processCharList(settings.prefixChars).filterNot(allSuffixChars::contains).plus("")
|
||||||
.distinct()
|
|
||||||
.joinToString("")
|
|
||||||
.ifEmpty(settings.layout::allChars)
|
|
||||||
|
|
||||||
allPossibleTags = allPossibleChars.flatMap { a -> allPossibleChars.map { b -> "$a$b".intern() } }.sortedWith(tagOrder)
|
allPossibleTagsLowercase = allSuffixChars
|
||||||
|
.flatMap { suffix -> allPrefixChars.map { prefix -> "$prefix$suffix" } }
|
||||||
|
.sortedWith(tagOrder)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun processCharList(charList: String): Set<String> {
|
||||||
|
return charList.toCharArray().map(Char::lowercase).toSet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/main/kotlin/org/acejump/modes/JumpMode.kt
Normal file
24
src/main/kotlin/org/acejump/modes/JumpMode.kt
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package org.acejump.modes
|
||||||
|
|
||||||
|
import org.acejump.action.AceTagAction
|
||||||
|
import org.acejump.config.AceConfig
|
||||||
|
import org.acejump.search.Tag
|
||||||
|
import org.acejump.session.SessionState
|
||||||
|
import org.acejump.session.TypeResult
|
||||||
|
|
||||||
|
open class JumpMode : SessionMode {
|
||||||
|
override val caretColor
|
||||||
|
get() = AceConfig.jumpModeColor
|
||||||
|
|
||||||
|
protected var wasUpperCase = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
override fun type(state: SessionState, charTyped: Char, acceptedTag: Tag?): TypeResult {
|
||||||
|
wasUpperCase = charTyped.isUpperCase()
|
||||||
|
return state.type(charTyped)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun accept(state: SessionState, acceptedTag: Tag) {
|
||||||
|
AceTagAction.JumpToSearchStart.invoke(acceptedTag, shiftMode = wasUpperCase, isFinal = true)
|
||||||
|
}
|
||||||
|
}
|
13
src/main/kotlin/org/acejump/modes/SessionMode.kt
Normal file
13
src/main/kotlin/org/acejump/modes/SessionMode.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package org.acejump.modes
|
||||||
|
|
||||||
|
import org.acejump.search.Tag
|
||||||
|
import org.acejump.session.SessionState
|
||||||
|
import org.acejump.session.TypeResult
|
||||||
|
import java.awt.Color
|
||||||
|
|
||||||
|
interface SessionMode {
|
||||||
|
val caretColor: Color
|
||||||
|
|
||||||
|
fun type(state: SessionState, charTyped: Char, acceptedTag: Tag?): TypeResult
|
||||||
|
fun accept(state: SessionState, acceptedTag: Tag)
|
||||||
|
}
|
@@ -4,6 +4,9 @@ enum class Pattern(val regex: String) {
|
|||||||
LINE_STARTS("^.|^\\n"),
|
LINE_STARTS("^.|^\\n"),
|
||||||
LINE_ENDS("\\n|\\Z"),
|
LINE_ENDS("\\n|\\Z"),
|
||||||
LINE_INDENTS("[^\\s].*|^\\n"),
|
LINE_INDENTS("[^\\s].*|^\\n"),
|
||||||
LINE_ALL_MARKS(LINE_ENDS.regex + "|" + LINE_STARTS.regex + "|" + LINE_INDENTS.regex),
|
ALL_WORDS("(?<=[^a-zA-Z0-9_]|\\A)[a-zA-Z0-9_]"),
|
||||||
ALL_WORDS("(?<=[^a-zA-Z0-9_]|\\A)[a-zA-Z0-9_]");
|
VIM_LWORD("(?<=[^a-zA-Z0-9_]|\\A)[a-zA-Z0-9_]"),
|
||||||
|
VIM_UWORD("(?<=\\s|\\A)[^\\s]"),
|
||||||
|
VIM_LWORD_END("[a-zA-Z0-9_](?=[^a-zA-Z0-9_]|\\Z)"),
|
||||||
|
VIM_UWORD_END("[^\\s](?=\\s|\\Z)")
|
||||||
}
|
}
|
||||||
|
@@ -3,121 +3,91 @@ package org.acejump.search
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
import it.unimi.dsi.fastutil.ints.IntArrayList
|
||||||
import org.acejump.boundaries.Boundaries
|
import org.acejump.boundaries.Boundaries
|
||||||
|
import org.acejump.clone
|
||||||
|
import org.acejump.config.AceConfig
|
||||||
import org.acejump.immutableText
|
import org.acejump.immutableText
|
||||||
import org.acejump.isWordPart
|
|
||||||
import org.acejump.matchesAt
|
import org.acejump.matchesAt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches editor text for matches of a [SearchQuery], and updates previous results when the user [type]s a character.
|
* Searches editor text for matches of a [SearchQuery], and updates previous results when the user [refineQuery]s a character.
|
||||||
*/
|
*/
|
||||||
internal class SearchProcessor private constructor(private val editor: Editor, query: SearchQuery, boundaries: Boundaries) {
|
class SearchProcessor private constructor(query: SearchQuery, private val results: MutableMap<Editor, IntArrayList>) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromChar(editor: Editor, char: Char, boundaries: Boundaries): SearchProcessor {
|
fun fromString(editors: List<Editor>, query: String, boundaries: Boundaries): SearchProcessor {
|
||||||
return SearchProcessor(editor, SearchQuery.Literal(char.toString()), boundaries)
|
return SearchProcessor(editors, SearchQuery.Literal(query), boundaries)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromRegex(editor: Editor, pattern: String, boundaries: Boundaries): SearchProcessor {
|
fun fromRegex(editors: List<Editor>, pattern: String, boundaries: Boundaries): SearchProcessor {
|
||||||
return SearchProcessor(editor, SearchQuery.RegularExpression(pattern), boundaries)
|
return SearchProcessor(editors, SearchQuery.RegularExpression(pattern), boundaries)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var query = query
|
private constructor(editors: List<Editor>, query: SearchQuery, boundaries: Boundaries) : this(query, mutableMapOf()) {
|
||||||
private set
|
|
||||||
|
|
||||||
var results = IntArrayList(0)
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
|
||||||
val regex = query.toRegex()
|
val regex = query.toRegex()
|
||||||
|
|
||||||
if (regex != null) {
|
if (regex != null) {
|
||||||
val offsetRange = boundaries.getOffsetRange(editor)
|
for (editor in editors) {
|
||||||
var result = regex.find(editor.immutableText, offsetRange.first)
|
val offsets = IntArrayList()
|
||||||
|
|
||||||
while (result != null) {
|
val offsetRange = boundaries.getOffsetRange(editor)
|
||||||
val index = result.range.first // For some reason regex matches can be out of bounds, but boundary check prevents an exception.
|
var result = regex.find(editor.immutableText, offsetRange.first)
|
||||||
val highlightEnd = index + query.getHighlightLength("", index)
|
|
||||||
|
|
||||||
if (highlightEnd > offsetRange.last) {
|
while (result != null) {
|
||||||
break
|
val index = result.range.first // For some reason regex matches can be out of bounds, but boundary check prevents an exception.
|
||||||
}
|
val highlightEnd = index + query.getHighlightLength("", index)
|
||||||
else if (boundaries.isOffsetInside(editor, index)) {
|
|
||||||
results.add(index)
|
if (highlightEnd > offsetRange.last) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
else if (boundaries.isOffsetInside(editor, index)) {
|
||||||
|
offsets.add(index)
|
||||||
|
}
|
||||||
|
|
||||||
|
result = result.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result.next()
|
results[editor] = offsets
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
internal var query = query
|
||||||
* Appends a character to the search query and removes all search results that no longer match the query. If the last typed character
|
private set
|
||||||
* transitioned the search query from a non-word to a word, it notifies the [Tagger] to reassign all tags. If the new query does not
|
|
||||||
* make sense because it would remove every result, the change is reverted and this function returns false.
|
|
||||||
*/
|
|
||||||
fun type(char: Char, tagger: Tagger): Boolean {
|
|
||||||
val newQuery = query.rawText + char
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val canMatchTag = tagger.canQueryMatchAnyTag(newQuery)
|
|
||||||
|
|
||||||
// If the typed character is not compatible with any existing tag or as a continuation of any previous occurrence, reject the query
|
val resultsCopy
|
||||||
// change and return false to indicate that nothing else should happen.
|
get() = results.clone()
|
||||||
|
|
||||||
if (newQuery.length > 1 && !canMatchTag && results.none { chars.matchesAt(it, newQuery, ignoreCase = true) }) {
|
val isQueryFinished
|
||||||
return false
|
get() = query.rawText.length >= AceConfig.minQueryLength
|
||||||
}
|
|
||||||
|
|
||||||
// If the typed character transitioned the search query from a non-word to a word, and the typed character does not belong to an
|
fun refineQuery(char: Char): Boolean {
|
||||||
// existing tag, we basically restart the search at the beginning of every new word, and unmark existing results so that all tags get
|
if (char == '\n') {
|
||||||
// regenerated immediately afterwards. Although this causes tags to change, it is one solution for conflicts between tag characters and
|
return true
|
||||||
// search query characters, and moving searches across word boundaries during search should be fairly uncommon.
|
|
||||||
|
|
||||||
if (!canMatchTag && newQuery.length >= 2 && !newQuery[newQuery.length - 2].isWordPart && char.isWordPart) {
|
|
||||||
query = SearchQuery.Literal(char.toString())
|
|
||||||
tagger.unmark()
|
|
||||||
|
|
||||||
val iter = results.iterator()
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
val movedOffset = iter.nextInt() + newQuery.length - 1
|
|
||||||
|
|
||||||
if (movedOffset < chars.length && chars[movedOffset].equals(char, ignoreCase = true)) {
|
|
||||||
iter.set(movedOffset)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
iter.remove()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
removeObsoleteResults(newQuery, tagger)
|
query = SearchQuery.Literal(query.rawText + char)
|
||||||
query = SearchQuery.Literal(newQuery)
|
removeObsoleteResults()
|
||||||
|
return isQueryFinished
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After updating the query, removes all results that no longer match the search query.
|
* After updating the query, removes all results that no longer match the search query.
|
||||||
*/
|
*/
|
||||||
private fun removeObsoleteResults(newQuery: String, tagger: Tagger) {
|
private fun removeObsoleteResults() {
|
||||||
val lastCharOffset = newQuery.lastIndex
|
val query = query.rawText
|
||||||
val lastChar = newQuery[lastCharOffset]
|
|
||||||
val ignoreCase = newQuery[0].isLowerCase()
|
|
||||||
val chars = editor.immutableText
|
|
||||||
|
|
||||||
val remaining = IntArrayList()
|
for (entry in results) {
|
||||||
val iter = results.iterator()
|
val editor = entry.key
|
||||||
|
val offsetIter = entry.value.iterator()
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
while (offsetIter.hasNext()) {
|
||||||
val offset = iter.nextInt()
|
val offset = offsetIter.nextInt()
|
||||||
val endOffset = offset + lastCharOffset
|
|
||||||
val lastTypedCharMatches = endOffset < chars.length && chars[endOffset].equals(lastChar, ignoreCase)
|
|
||||||
|
|
||||||
if (lastTypedCharMatches || tagger.isQueryCompatibleWithTagAt(newQuery, offset)) {
|
if (!editor.immutableText.matchesAt(offset, query, ignoreCase = true)) {
|
||||||
remaining.add(offset)
|
offsetIter.remove()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
results = remaining
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ internal sealed class SearchQuery {
|
|||||||
* Each occurrence must either match the entire query, or match the query up to a point so that the rest of the query matches the
|
* Each occurrence must either match the entire query, or match the query up to a point so that the rest of the query matches the
|
||||||
* beginning of a tag at the location of the occurrence.
|
* beginning of a tag at the location of the occurrence.
|
||||||
*/
|
*/
|
||||||
class Literal(override var rawText: String) : SearchQuery() {
|
class Literal(override val rawText: String) : SearchQuery() {
|
||||||
init {
|
init {
|
||||||
require(rawText.isNotEmpty())
|
require(rawText.isNotEmpty())
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ internal sealed class SearchQuery {
|
|||||||
/**
|
/**
|
||||||
* Searches for all matches of a regular expression.
|
* Searches for all matches of a regular expression.
|
||||||
*/
|
*/
|
||||||
class RegularExpression(private var pattern: String) : SearchQuery() {
|
class RegularExpression(private val pattern: String) : SearchQuery() {
|
||||||
override val rawText = ""
|
override val rawText = ""
|
||||||
|
|
||||||
override fun getHighlightLength(text: CharSequence, offset: Int): Int {
|
override fun getHighlightLength(text: CharSequence, offset: Int): Int {
|
||||||
|
@@ -1,193 +0,0 @@
|
|||||||
package org.acejump.search
|
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import it.unimi.dsi.fastutil.ints.*
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
|
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
|
||||||
import org.acejump.config.AceConfig
|
|
||||||
import org.acejump.immutableText
|
|
||||||
import org.acejump.input.KeyLayoutCache
|
|
||||||
import org.acejump.isWordPart
|
|
||||||
import org.acejump.wordEndPlus
|
|
||||||
import java.util.*
|
|
||||||
import kotlin.collections.HashMap
|
|
||||||
import kotlin.collections.HashSet
|
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Solves the Tag Assignment Problem. The tag assignment problem can be stated
|
|
||||||
* thusly: Given a set of indices I in document d, and a set of tags T, find a
|
|
||||||
* bijection f: T*⊂T → I*⊂I s.t. d[i..k] + t ∉ d[i'..(k + |t|)], ∀ i' ∈ I\{i},
|
|
||||||
* ∀ k ∈ (i, |d|-|t|], where t ∈ T, i ∈ I. Maximize |I*|. This can be relaxed
|
|
||||||
* to t=t[0] and ∀ k ∈ (i, i+K] for some fixed K, in most natural documents.
|
|
||||||
*
|
|
||||||
* More concretely, tags are typically two-character strings containing alpha-
|
|
||||||
* numeric symbols. Documents are plaintext files. Indices are produced by a
|
|
||||||
* search query of length N, i.e. the preceding N characters of every index i in
|
|
||||||
* document d are identical. For characters proceeding d[i], all bets are off.
|
|
||||||
* We can assume that P(d[i]|d[i-1]) has some structure for d~D. Ultimately, we
|
|
||||||
* want a fast algorithm which maximizes the number of tagged document indices.
|
|
||||||
*
|
|
||||||
* Tags are used by the typist to select indices within a document. To select an
|
|
||||||
* index, the typist starts by activating AceJump and searching for a character.
|
|
||||||
* As soon as the first character is received, we begin to scan the document for
|
|
||||||
* matching locations and assign as many valid tags as possible. When subsequent
|
|
||||||
* characters are received, we refine the search results to match either:
|
|
||||||
*
|
|
||||||
* 1.) The plaintext query alone, or
|
|
||||||
* 2.) The concatenation of plaintext query and partial tag
|
|
||||||
*
|
|
||||||
* The constraint in paragraph no. 1 tries to impose the following criteria:
|
|
||||||
*
|
|
||||||
* 1.) All valid key sequences will lead to a unique location in the document
|
|
||||||
* 2.) All indices in the document will be reachable by a short key sequence
|
|
||||||
*
|
|
||||||
* If there is an insufficient number of two-character tags to cover every index
|
|
||||||
* (which typically occurs when the user searches for a common character within
|
|
||||||
* a long document), then we attempt to maximize the number of tags assigned to
|
|
||||||
* document indices. The key is, all tags must be assigned as soon as possible,
|
|
||||||
* i.e. as soon as the first character is received or whenever the user ceases
|
|
||||||
* typing (at the very latest). Once assigned, a visible tag must never change
|
|
||||||
* at any time during the selection process, so as not to confuse the user.
|
|
||||||
*/
|
|
||||||
|
|
||||||
internal class Solver private constructor(
|
|
||||||
private val editor: Editor,
|
|
||||||
private val queryLength: Int,
|
|
||||||
private val newResults: IntList,
|
|
||||||
private val allResults: IntList
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
fun solve(
|
|
||||||
editor: Editor, query: SearchQuery, newResults: IntList, allResults: IntList, tags: List<String>, cache: EditorOffsetCache
|
|
||||||
): Map<String, Int> {
|
|
||||||
return Solver(editor, max(1, query.rawText.length), newResults, allResults).map(tags, cache)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private var newTags = Object2IntOpenHashMap<String>(KeyLayoutCache.allPossibleTags.size)
|
|
||||||
private val newTagIndices = IntOpenHashSet()
|
|
||||||
|
|
||||||
private var allWordFragments = HashSet<String>(allResults.size).apply {
|
|
||||||
val iter = allResults.iterator()
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
forEachWordFragment(iter.nextInt()) { add(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun map(availableTags: List<String>, cache: EditorOffsetCache): Map<String, Int> {
|
|
||||||
val eligibleSitesByTag = HashMap<String, IntList>(100)
|
|
||||||
val tagsByFirstLetter = availableTags.groupBy { it[0] }
|
|
||||||
|
|
||||||
val iter = newResults.iterator()
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
val site = iter.nextInt()
|
|
||||||
|
|
||||||
for ((firstLetter, tags) in tagsByFirstLetter.entries) {
|
|
||||||
if (canTagBeginWithChar(site, firstLetter)) {
|
|
||||||
for (tag in tags) {
|
|
||||||
eligibleSitesByTag.getOrPut(tag) { IntArrayList(10) }.add(site)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val matchingSites = HashMap<IntList, IntArray>()
|
|
||||||
val matchingSitesAsArrays = IdentityHashMap<String, IntArray>() // Keys are guaranteed to be from a single collection.
|
|
||||||
|
|
||||||
val siteOrder = siteOrder(cache)
|
|
||||||
val tagOrder = KeyLayoutCache.tagOrder
|
|
||||||
.thenComparingInt { eligibleSitesByTag.getValue(it).size }
|
|
||||||
.thenBy(AceConfig.layout.priority(String::last))
|
|
||||||
|
|
||||||
val sortedTags = eligibleSitesByTag.keys.toMutableList().apply {
|
|
||||||
sortWith(tagOrder)
|
|
||||||
}
|
|
||||||
|
|
||||||
for ((key, value) in eligibleSitesByTag.entries) {
|
|
||||||
matchingSitesAsArrays[key] = matchingSites.getOrPut(value) {
|
|
||||||
value.toIntArray().apply { IntArrays.mergeSort(this, siteOrder) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var totalAssigned = 0
|
|
||||||
|
|
||||||
for (tag in sortedTags) {
|
|
||||||
if (totalAssigned == newResults.size) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tryToAssignTag(tag, matchingSitesAsArrays.getValue(tag))) {
|
|
||||||
totalAssigned++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return newTags
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun tryToAssignTag(tag: String, sites: IntArray): Boolean {
|
|
||||||
if (newTags.containsKey(tag)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val index = sites.firstOrNull { it !in newTagIndices } ?: return false
|
|
||||||
|
|
||||||
@Suppress("ReplacePutWithAssignment")
|
|
||||||
newTags.put(tag, index)
|
|
||||||
newTagIndices.add(index)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun siteOrder(cache: EditorOffsetCache) = IntComparator { a, b ->
|
|
||||||
val aIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
|
|
||||||
val bIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
|
|
||||||
|
|
||||||
if (aIsVisible != bIsVisible) {
|
|
||||||
// Sites in immediate view should come first.
|
|
||||||
return@IntComparator if (aIsVisible) -1 else 1
|
|
||||||
}
|
|
||||||
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val aIsNotWordStart = chars[max(0, a - 1)].isWordPart
|
|
||||||
val bIsNotWordStart = chars[max(0, b - 1)].isWordPart
|
|
||||||
|
|
||||||
if (aIsNotWordStart != bIsNotWordStart) {
|
|
||||||
// Ensure that the first letter of a word is prioritized for tagging.
|
|
||||||
return@IntComparator if (bIsNotWordStart) -1 else 1
|
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
|
||||||
a < b -> -1
|
|
||||||
a > b -> 1
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun canTagBeginWithChar(site: Int, char: Char): Boolean {
|
|
||||||
if (char.toString() in allWordFragments) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
forEachWordFragment(site) {
|
|
||||||
if (it + char in allWordFragments) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun forEachWordFragment(site: Int, callback: (String) -> Unit) {
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val left = max(0, site + queryLength - 1)
|
|
||||||
val right = chars.wordEndPlus(site)
|
|
||||||
|
|
||||||
val builder = StringBuilder(1 + right - left)
|
|
||||||
|
|
||||||
for (i in left..right) {
|
|
||||||
builder.append(chars[i].toLowerCase())
|
|
||||||
callback(builder.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
13
src/main/kotlin/org/acejump/search/Tag.kt
Normal file
13
src/main/kotlin/org/acejump/search/Tag.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package org.acejump.search
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
|
||||||
|
data class Tag(val editor: Editor, val offset: Int) {
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return other is Tag && other.offset == offset && other.editor === editor
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return (offset * 31) + editor.hashCode()
|
||||||
|
}
|
||||||
|
}
|
@@ -1,198 +1,117 @@
|
|||||||
package org.acejump.search
|
package org.acejump.search
|
||||||
|
|
||||||
import com.google.common.collect.HashBiMap
|
import com.google.common.collect.ArrayListMultimap
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import it.unimi.dsi.fastutil.ints.IntArrayList
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntList
|
import it.unimi.dsi.fastutil.ints.IntList
|
||||||
import org.acejump.ExternalUsage
|
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
import org.acejump.boundaries.EditorOffsetCache
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
import org.acejump.boundaries.StandardBoundaries.VISIBLE_ON_SCREEN
|
||||||
import org.acejump.immutableText
|
import org.acejump.immutableText
|
||||||
import org.acejump.input.KeyLayoutCache.allPossibleTags
|
import org.acejump.input.KeyLayoutCache
|
||||||
import org.acejump.isWordPart
|
import org.acejump.isWordPart
|
||||||
import org.acejump.matchesAt
|
import org.acejump.view.TagMarker
|
||||||
import org.acejump.view.Tag
|
|
||||||
import java.util.AbstractMap.SimpleImmutableEntry
|
|
||||||
import kotlin.collections.component1
|
import kotlin.collections.component1
|
||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns tags to search occurrences, updates them when the search query changes, and requests a jump if the search query matches a tag.
|
* Assigns tags to search occurrences.
|
||||||
|
* The ordering of [editors] may be used to prioritize tagging editors earlier in the list in case of conflicts.
|
||||||
*/
|
*/
|
||||||
internal class Tagger(private val editor: Editor) {
|
class Tagger(private val editors: List<Editor>, results: Map<Editor, IntList>) {
|
||||||
private var tagMap = HashBiMap.create<String, Int>()
|
private var tagMap: Map<String, Tag>
|
||||||
|
private var typedTag = ""
|
||||||
|
|
||||||
val hasTags
|
internal val markers: Map<Editor, Collection<TagMarker>>
|
||||||
get() = tagMap.isNotEmpty()
|
get() {
|
||||||
|
val markers = ArrayListMultimap.create<Editor, TagMarker>(editors.size, min(tagMap.values.size, 40))
|
||||||
|
|
||||||
@ExternalUsage
|
for ((mark, tag) in tagMap) {
|
||||||
val tags
|
val marker = TagMarker.create(mark, tag.offset, typedTag)
|
||||||
get() = tagMap.map { SimpleImmutableEntry(it.key, it.value) }.sortedBy { it.value }
|
markers.put(tag.editor, marker)
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes all markers, allowing them to be regenerated from scratch.
|
|
||||||
*/
|
|
||||||
fun unmark() {
|
|
||||||
tagMap = HashBiMap.create()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Assigns tags to as many results as possible, keeping previously assigned tags. Returns a [TaggingResult.Jump] if the current search
|
|
||||||
* query matches any existing tag and we should jump to it and end the session, or [TaggingResult.Mark] to continue the session with
|
|
||||||
* updated tag markers.
|
|
||||||
*
|
|
||||||
* Note that the [results] collection will be mutated.
|
|
||||||
*/
|
|
||||||
fun markOrJump(query: SearchQuery, results: IntList): TaggingResult {
|
|
||||||
val isRegex = query is SearchQuery.RegularExpression
|
|
||||||
val queryText = if (isRegex) " ${query.rawText}" else query.rawText[0] + query.rawText.drop(1).toLowerCase()
|
|
||||||
|
|
||||||
val availableTags = allPossibleTags.filter { !queryText.endsWith(it[0]) && it !in tagMap }
|
|
||||||
|
|
||||||
if (!isRegex) {
|
|
||||||
for (entry in tagMap.entries) {
|
|
||||||
if (entry solves queryText) {
|
|
||||||
return TaggingResult.Jump(entry.value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryText.length == 1) {
|
return markers.asMap()
|
||||||
removeResultsWithOverlappingTags(results)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRegex || tagMap.isEmpty()) {
|
init {
|
||||||
tagMap = assignTagsAndMerge(results, availableTags, query, queryText)
|
val caches = results.keys.associateWith { EditorOffsetCache.new() }
|
||||||
}
|
|
||||||
|
|
||||||
return TaggingResult.Mark(createTagMarkers(results, query.rawText.ifEmpty { null }))
|
sortResults(results, caches)
|
||||||
|
|
||||||
|
val tagSites = results
|
||||||
|
.flatMap { (editor, sites) -> sites.map { site -> Tag(editor, site) } }
|
||||||
|
.sortedWith(siteOrder(editors, caches))
|
||||||
|
|
||||||
|
tagMap = KeyLayoutCache.allPossibleTagsLowercase.zip(tagSites).toMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
internal fun type(char: Char): TaggingResult {
|
||||||
* Assigns as many unassigned tags as possible, and merges them with the existing compatible tags.
|
val newTypedTag = typedTag + char.lowercaseChar()
|
||||||
*/
|
val matchingTag = tagMap[newTypedTag]
|
||||||
private fun assignTagsAndMerge(results: IntList, availableTags: List<String>, query: SearchQuery, queryText: String): HashBiMap<String, Int> {
|
if (matchingTag != null) {
|
||||||
val cache = EditorOffsetCache.new()
|
return TaggingResult.Accept(matchingTag)
|
||||||
|
|
||||||
results.sort { a, b ->
|
|
||||||
val aIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
|
|
||||||
val bIsVisible = StandardBoundaries.VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
|
|
||||||
|
|
||||||
when {
|
|
||||||
aIsVisible && !bIsVisible -> -1
|
|
||||||
bIsVisible && !aIsVisible -> 1
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val allAssignedTags = mutableMapOf<String, Int>()
|
val newTagMap = tagMap.filter { it.key.startsWith(newTypedTag) }
|
||||||
val oldCompatibleTags = tagMap.filter { isTagCompatibleWithQuery(it.key, it.value, queryText) || it.value in results }
|
if (newTagMap.isEmpty()) {
|
||||||
val vacantResults: IntList
|
return TaggingResult.Nothing
|
||||||
|
|
||||||
if (oldCompatibleTags.isEmpty()) {
|
|
||||||
vacantResults = results
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
vacantResults = IntArrayList()
|
|
||||||
|
|
||||||
val iter = results.iterator()
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
val offset = iter.nextInt()
|
|
||||||
|
|
||||||
if (offset !in oldCompatibleTags.values) {
|
|
||||||
vacantResults.add(offset)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allAssignedTags.putAll(oldCompatibleTags)
|
typedTag = newTypedTag
|
||||||
allAssignedTags.putAll(Solver.solve(editor, query, vacantResults, results, availableTags, cache))
|
tagMap = newTagMap
|
||||||
|
return TaggingResult.Mark(markers)
|
||||||
return allAssignedTags.mapKeysTo(HashBiMap.create(allAssignedTags.size)) { (tag, _) ->
|
|
||||||
// Avoid matching query - will trigger a jump.
|
|
||||||
// TODO: lift this constraint.
|
|
||||||
val queryEndsWith = queryText.endsWith(tag[0]) || queryText.endsWith(tag)
|
|
||||||
|
|
||||||
if (!queryEndsWith && canShortenTag(tag, allAssignedTags))
|
|
||||||
tag[0].toString()
|
|
||||||
else
|
|
||||||
tag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private infix fun Map.Entry<String, Int>.solves(query: String): Boolean {
|
|
||||||
return query.endsWith(key, true) && isTagCompatibleWithQuery(key, value, query)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isTagCompatibleWithQuery(tag: String, offset: Int, query: String): Boolean {
|
|
||||||
return editor.immutableText.matchesAt(offset, getPlaintextPortion(query, tag), ignoreCase = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isQueryCompatibleWithTagAt(query: String, offset: Int): Boolean {
|
|
||||||
return tagMap.inverse()[offset].let { it != null && isTagCompatibleWithQuery(it, offset, query) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun canQueryMatchAnyTag(query: String): Boolean {
|
|
||||||
return tagMap.any { (tag, offset) ->
|
|
||||||
val tagPortion = getTagPortion(query, tag)
|
|
||||||
tagPortion.isNotEmpty() && tag.startsWith(tagPortion, ignoreCase = true) && isTagCompatibleWithQuery(tag, offset, query)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeResultsWithOverlappingTags(results: IntList) {
|
|
||||||
val iter = results.iterator()
|
|
||||||
val chars = editor.immutableText
|
|
||||||
|
|
||||||
while (iter.hasNext()) {
|
|
||||||
if (!chars.canTagWithoutOverlap(iter.nextInt())) {
|
|
||||||
iter.remove() // Very uncommon, so slow removal is fine.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createTagMarkers(results: IntList, literalQueryText: String?): List<Tag> {
|
|
||||||
val tagMapInv = tagMap.inverse()
|
|
||||||
return results.mapNotNull { index -> tagMapInv[index]?.let { tag -> Tag.create(editor, tag, index, literalQueryText) } }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
private fun CharSequence.canTagWithoutOverlap(loc: Int) = when {
|
private fun sortResults(results: Map<Editor, IntList>, caches: Map<Editor, EditorOffsetCache>) {
|
||||||
loc - 1 < 0 -> true
|
for ((editor, offsets) in results) {
|
||||||
loc + 1 >= length -> true
|
val cache = caches.getValue(editor)
|
||||||
this[loc] isUnlike this[loc - 1] -> true
|
|
||||||
this[loc] isUnlike this[loc + 1] -> true
|
|
||||||
this[loc] != this[loc - 1] -> true
|
|
||||||
this[loc] != this[loc + 1] -> true
|
|
||||||
this[loc + 1] == '\r' || this[loc + 1] == '\n' -> true
|
|
||||||
this[loc - 1] == this[loc] && this[loc] == this[loc + 1] -> false
|
|
||||||
this[loc + 1].isWhitespace() && this[(loc + 2).coerceAtMost(length - 1)].isWhitespace() -> true
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
private infix fun Char.isUnlike(other: Char): Boolean {
|
offsets.sort { a, b ->
|
||||||
return this.isWordPart xor other.isWordPart || this.isWhitespace() xor other.isWhitespace()
|
val aIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(editor, a, cache)
|
||||||
}
|
val bIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(editor, b, cache)
|
||||||
|
|
||||||
private fun getPlaintextPortion(query: String, tag: String) = when {
|
when {
|
||||||
query.endsWith(tag, true) -> query.dropLast(tag.length)
|
aIsVisible && !bIsVisible -> -1
|
||||||
query.endsWith(tag.first(), true) -> query.dropLast(1)
|
bIsVisible && !aIsVisible -> 1
|
||||||
else -> query
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTagPortion(query: String, tag: String) = when {
|
|
||||||
query.endsWith(tag, true) -> query.takeLast(tag.length)
|
|
||||||
query.endsWith(tag.first(), true) -> query.takeLast(1)
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun canShortenTag(tag: String, tagMap: Map<String, Int>): Boolean {
|
|
||||||
for (other in tagMap.keys) {
|
|
||||||
if (tag != other && tag[0] == other[0]) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun siteOrder(editorPriority: List<Editor>, caches: Map<Editor, EditorOffsetCache>) = Comparator<Tag> { a, b ->
|
||||||
|
val aEditor = a.editor
|
||||||
|
val bEditor = b.editor
|
||||||
|
|
||||||
|
if (aEditor !== bEditor) {
|
||||||
|
val aEditorIndex = editorPriority.indexOf(aEditor)
|
||||||
|
val bEditorIndex = editorPriority.indexOf(bEditor)
|
||||||
|
// For multiple editors, prioritize them based on the provided order.
|
||||||
|
return@Comparator if (aEditorIndex < bEditorIndex) -1 else 1
|
||||||
|
}
|
||||||
|
|
||||||
|
val aIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(aEditor, a.offset, caches.getValue(aEditor))
|
||||||
|
val bIsVisible = VISIBLE_ON_SCREEN.isOffsetInside(bEditor, b.offset, caches.getValue(bEditor))
|
||||||
|
if (aIsVisible != bIsVisible) {
|
||||||
|
// Sites in immediate view should come first.
|
||||||
|
return@Comparator if (aIsVisible) -1 else 1
|
||||||
|
}
|
||||||
|
|
||||||
|
val aIsNotWordStart = aEditor.immutableText[max(0, a.offset - 1)].isWordPart
|
||||||
|
val bIsNotWordStart = bEditor.immutableText[max(0, b.offset - 1)].isWordPart
|
||||||
|
if (aIsNotWordStart != bIsNotWordStart) {
|
||||||
|
// Ensure that the first letter of a word is prioritized for tagging.
|
||||||
|
return@Comparator if (bIsNotWordStart) -1 else 1
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
a.offset < b.offset -> -1
|
||||||
|
a.offset > b.offset -> 1
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
package org.acejump.search
|
package org.acejump.search
|
||||||
|
|
||||||
import org.acejump.view.Tag
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.acejump.view.TagMarker
|
||||||
|
|
||||||
internal sealed class TaggingResult {
|
internal sealed class TaggingResult {
|
||||||
class Jump(val offset: Int) : TaggingResult()
|
object Nothing : TaggingResult()
|
||||||
class Mark(val tags: List<Tag>) : TaggingResult()
|
class Accept(val tag: Tag) : TaggingResult()
|
||||||
|
class Mark(val markers: Map<Editor, Collection<TagMarker>>) : TaggingResult()
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,22 @@ internal data class EditorSettings(private val isBlockCursor: Boolean, private v
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun startEditing(editor: Editor) {
|
||||||
|
editor.document.setReadOnly(isReadOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun stopEditing(editor: Editor) {
|
||||||
|
editor.document.setReadOnly(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onTagAccepted(editor: Editor) = editor.let {
|
||||||
|
it.settings.isBlockCursor = isBlockCursor
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onTagUnaccepted(editor: Editor) = editor.let {
|
||||||
|
it.settings.isBlockCursor = true
|
||||||
|
}
|
||||||
|
|
||||||
fun restore(editor: Editor) {
|
fun restore(editor: Editor) {
|
||||||
val settings = editor.settings
|
val settings = editor.settings
|
||||||
val document = editor.document
|
val document = editor.document
|
||||||
|
@@ -1,212 +1,180 @@
|
|||||||
package org.acejump.session
|
package org.acejump.session
|
||||||
|
|
||||||
import com.intellij.openapi.actionSystem.DataContext
|
import com.intellij.codeInsight.hint.HintManagerImpl
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.ScrollType
|
import com.intellij.openapi.editor.ScrollType
|
||||||
import com.intellij.openapi.editor.actionSystem.TypedActionHandler
|
|
||||||
import com.intellij.openapi.editor.colors.EditorColors
|
import com.intellij.openapi.editor.colors.EditorColors
|
||||||
import org.acejump.ExternalUsage
|
import com.intellij.openapi.editor.colors.impl.AbstractColorsScheme
|
||||||
import org.acejump.action.TagJumper
|
import it.unimi.dsi.fastutil.ints.IntList
|
||||||
import org.acejump.action.TagVisitor
|
|
||||||
import org.acejump.boundaries.Boundaries
|
import org.acejump.boundaries.Boundaries
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
import org.acejump.boundaries.StandardBoundaries
|
||||||
import org.acejump.config.AceConfig
|
import org.acejump.config.AceConfig
|
||||||
import org.acejump.input.EditorKeyListener
|
import org.acejump.input.EditorKeyListener
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.input.JumpModeTracker
|
|
||||||
import org.acejump.input.KeyLayoutCache
|
import org.acejump.input.KeyLayoutCache
|
||||||
|
import org.acejump.modes.JumpMode
|
||||||
|
import org.acejump.modes.SessionMode
|
||||||
import org.acejump.search.Pattern
|
import org.acejump.search.Pattern
|
||||||
import org.acejump.search.SearchProcessor
|
import org.acejump.search.SearchProcessor
|
||||||
import org.acejump.search.Tagger
|
import org.acejump.search.SearchQuery
|
||||||
import org.acejump.search.TaggingResult
|
import org.acejump.search.Tag
|
||||||
|
import org.acejump.session.TypeResult.AcceptTag
|
||||||
|
import org.acejump.session.TypeResult.ChangeMode
|
||||||
|
import org.acejump.session.TypeResult.ChangeState
|
||||||
|
import org.acejump.session.TypeResult.EndSession
|
||||||
|
import org.acejump.session.TypeResult.Nothing
|
||||||
import org.acejump.view.TagCanvas
|
import org.acejump.view.TagCanvas
|
||||||
|
import org.acejump.view.TagMarker
|
||||||
import org.acejump.view.TextHighlighter
|
import org.acejump.view.TextHighlighter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages an AceJump session for a single [Editor].
|
* Manages an AceJump session for a single [Editor].
|
||||||
*/
|
*/
|
||||||
class Session(private val editor: Editor) {
|
class Session(private val mainEditor: Editor, private val jumpEditors: List<Editor>) {
|
||||||
private companion object {
|
private val editorSettings = EditorSettings.setup(mainEditor)
|
||||||
private val defaultBoundaries
|
private lateinit var mode: SessionMode
|
||||||
get() = if (AceConfig.searchWholeFile) StandardBoundaries.WHOLE_FILE else StandardBoundaries.VISIBLE_ON_SCREEN
|
|
||||||
}
|
|
||||||
|
|
||||||
private val originalSettings = EditorSettings.setup(editor)
|
private var state: SessionState? = null
|
||||||
|
|
||||||
private val jumpModeTracker = JumpModeTracker()
|
private var acceptedTag: Tag? = null
|
||||||
private var jumpMode = JumpMode.DISABLED
|
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
|
||||||
if (value === JumpMode.DISABLED) {
|
if (value != null) {
|
||||||
end()
|
tagCanvases.values.forEach(TagCanvas::removeMarkers)
|
||||||
}
|
editorSettings.onTagAccepted(mainEditor)
|
||||||
else {
|
|
||||||
searchProcessor?.let { textHighlighter.render(it.results, it.query, jumpMode) }
|
|
||||||
editor.colorsScheme.setColor(EditorColors.CARET_COLOR, value.caretColor)
|
|
||||||
editor.contentComponent.repaint()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var searchProcessor: SearchProcessor? = null
|
private val textHighlighter = TextHighlighter()
|
||||||
private var tagger = Tagger(editor)
|
private val tagCanvases = jumpEditors.associateWith(::TagCanvas)
|
||||||
|
|
||||||
private val tagJumper
|
var defaultBoundary: Boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
|
||||||
get() = TagJumper(editor, jumpMode, searchProcessor)
|
|
||||||
|
|
||||||
private val tagVisitor
|
private val actions = object : SessionActions {
|
||||||
get() = searchProcessor?.let { TagVisitor(editor, it, tagJumper) }
|
override fun showHighlights(results: Map<Editor, IntList>, query: SearchQuery) {
|
||||||
|
textHighlighter.renderOccurrences(results, query)
|
||||||
|
}
|
||||||
|
|
||||||
private val textHighlighter = TextHighlighter(editor)
|
override fun hideHighlights() {
|
||||||
private val tagCanvas = TagCanvas(editor)
|
textHighlighter.reset()
|
||||||
|
}
|
||||||
|
|
||||||
@ExternalUsage
|
override fun setTagMarkers(markers: Map<Editor, Collection<TagMarker>>) {
|
||||||
val tags
|
for ((editor, canvas) in tagCanvases) {
|
||||||
get() = tagger.tags
|
canvas.setMarkers(markers[editor].orEmpty())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
KeyLayoutCache.ensureInitialized(AceConfig.settings)
|
KeyLayoutCache.ensureInitialized(AceConfig.settings)
|
||||||
|
EditorKeyListener.attach(mainEditor) { editor, charTyped, _ -> typeCharacter(editor, charTyped) }
|
||||||
EditorKeyListener.attach(editor, object : TypedActionHandler {
|
|
||||||
override fun execute(editor: Editor, charTyped: Char, context: DataContext) {
|
|
||||||
var processor = searchProcessor
|
|
||||||
val hadTags = tagger.hasTags
|
|
||||||
|
|
||||||
if (processor == null) {
|
|
||||||
processor = SearchProcessor.fromChar(editor, charTyped, defaultBoundaries).also { searchProcessor = it }
|
|
||||||
}
|
|
||||||
else if (!processor.type(charTyped, tagger)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
updateSearch(processor, markImmediately = hadTags, shiftMode = charTyped.isUpperCase())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private fun typeCharacter(editor: Editor, charTyped: Char) {
|
||||||
* Updates text highlights and tag markers according to the current search state. Dispatches jumps if the search query matches a tag.
|
val state = state ?: return
|
||||||
* If all tags are outside view, scrolls to the closest one.
|
|
||||||
*/
|
|
||||||
private fun updateSearch(processor: SearchProcessor, markImmediately: Boolean, shiftMode: Boolean = false) {
|
|
||||||
val query = processor.query
|
|
||||||
val results = processor.results
|
|
||||||
|
|
||||||
textHighlighter.render(results, query, jumpMode)
|
editorSettings.startEditing(editor)
|
||||||
|
val result = mode.type(state, charTyped, acceptedTag)
|
||||||
|
editorSettings.stopEditing(editor)
|
||||||
|
|
||||||
if (!markImmediately && query.rawText.let { it.length < AceConfig.minQueryLength && it.all(Char::isLetterOrDigit) }) {
|
when (result) {
|
||||||
return
|
Nothing -> return
|
||||||
}
|
is ChangeState -> this.state = result.state
|
||||||
|
is ChangeMode -> setMode(result.mode)
|
||||||
|
|
||||||
when (val result = tagger.markOrJump(query, results.clone())) {
|
is AcceptTag -> {
|
||||||
is TaggingResult.Jump -> {
|
acceptedTag = result.tag
|
||||||
tagJumper.jump(result.offset, shiftMode)
|
mode.accept(state, result.tag)
|
||||||
tagCanvas.removeMarkers()
|
|
||||||
end()
|
end()
|
||||||
}
|
}
|
||||||
|
|
||||||
is TaggingResult.Mark -> {
|
EndSession -> end()
|
||||||
val tags = result.tags
|
|
||||||
tagCanvas.setMarkers(tags)
|
|
||||||
|
|
||||||
val cache = EditorOffsetCache.new()
|
|
||||||
val boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
|
|
||||||
|
|
||||||
if (tags.none { boundaries.isOffsetInside(editor, it.offsetL, cache) || boundaries.isOffsetInside(editor, it.offsetR, cache) }) {
|
|
||||||
tagVisitor?.scrollToClosest()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setMode(mode: SessionMode) {
|
||||||
|
this.mode = mode
|
||||||
|
mainEditor.colorsScheme.setColor(EditorColors.CARET_COLOR, mode.caretColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startJumpMode() {
|
||||||
|
startJumpMode(::JumpMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startJumpMode(mode: () -> JumpMode) {
|
||||||
|
if (this::mode.isInitialized && mode is JumpMode) {
|
||||||
|
end()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this::mode.isInitialized) {
|
||||||
|
restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
setMode(mode())
|
||||||
|
state = SessionState.WaitForKey(actions, jumpEditors, defaultBoundary)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
|
* Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
|
||||||
*/
|
*/
|
||||||
fun startRegexSearch(pattern: String, boundaries: Boundaries) {
|
fun startRegexSearch(pattern: Pattern) {
|
||||||
tagger = Tagger(editor)
|
if (!this::mode.isInitialized) {
|
||||||
tagCanvas.setMarkers(emptyList())
|
setMode(JumpMode())
|
||||||
|
|
||||||
val processor = SearchProcessor.fromRegex(editor, pattern, boundaries.intersection(defaultBoundaries)).also { searchProcessor = it }
|
|
||||||
updateSearch(processor, markImmediately = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts a regular expression search. If a search was already active, it will be reset alongside its tags and highlights.
|
|
||||||
*/
|
|
||||||
fun startRegexSearch(pattern: Pattern, boundaries: Boundaries) {
|
|
||||||
startRegexSearch(pattern.regex, boundaries)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See [JumpModeTracker.cycle].
|
|
||||||
*/
|
|
||||||
fun cycleNextJumpMode() {
|
|
||||||
jumpMode = jumpModeTracker.cycle(forward = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See [JumpModeTracker.cycle].
|
|
||||||
*/
|
|
||||||
fun cyclePreviousJumpMode() {
|
|
||||||
jumpMode = jumpModeTracker.cycle(forward = false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See [JumpModeTracker.toggle]
|
|
||||||
*/
|
|
||||||
fun toggleJumpMode(newMode: JumpMode) {
|
|
||||||
jumpMode = jumpModeTracker.toggle(newMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See [TagVisitor.visitPrevious]. If there are no tags, nothing happens.
|
|
||||||
*/
|
|
||||||
fun visitPreviousTag() {
|
|
||||||
if (tagVisitor?.visitPrevious() == true) {
|
|
||||||
end()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (canvas in tagCanvases.values) {
|
||||||
|
canvas.setMarkers(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
val processor = SearchProcessor.fromRegex(jumpEditors, pattern.regex, defaultBoundary)
|
||||||
|
textHighlighter.renderOccurrences(processor.resultsCopy, processor.query)
|
||||||
|
|
||||||
|
state = SessionState.SelectTag(actions, jumpEditors, processor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun tagImmediately() {
|
||||||
* See [TagVisitor.visitNext]. If there are no tags, nothing happens.
|
typeCharacter(mainEditor, '\n')
|
||||||
*/
|
|
||||||
fun visitNextTag() {
|
|
||||||
if (tagVisitor?.visitNext() == true) {
|
|
||||||
end()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends this session.
|
* Ends this session.
|
||||||
*/
|
*/
|
||||||
fun end() {
|
fun end() {
|
||||||
SessionManager.end(editor)
|
SessionManager.end(mainEditor)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears any currently active search, tags, and highlights. Does not reset [JumpMode].
|
* Clears any currently active search, tags, and highlights.
|
||||||
*/
|
*/
|
||||||
fun restart() {
|
fun restart() {
|
||||||
tagger = Tagger(editor)
|
state = null
|
||||||
searchProcessor = null
|
acceptedTag = null
|
||||||
tagCanvas.removeMarkers()
|
tagCanvases.values.forEach(TagCanvas::removeMarkers)
|
||||||
textHighlighter.reset()
|
textHighlighter.reset()
|
||||||
|
|
||||||
|
HintManagerImpl.getInstanceImpl().hideAllHints()
|
||||||
|
editorSettings.onTagUnaccepted(mainEditor)
|
||||||
|
mainEditor.colorsScheme.setColor(EditorColors.CARET_COLOR, mode.caretColor)
|
||||||
|
jumpEditors.forEach { it.contentComponent.repaint() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should only be used from [SessionManager] to dispose a successfully ended session.
|
* Should only be used from [SessionManager] to dispose a successfully ended session.
|
||||||
*/
|
*/
|
||||||
internal fun dispose() {
|
internal fun dispose() {
|
||||||
tagger = Tagger(editor)
|
tagCanvases.values.forEach(TagCanvas::unbind)
|
||||||
EditorKeyListener.detach(editor)
|
|
||||||
tagCanvas.unbind()
|
|
||||||
textHighlighter.reset()
|
textHighlighter.reset()
|
||||||
|
EditorKeyListener.detach(mainEditor)
|
||||||
|
|
||||||
if (!editor.isDisposed) {
|
if (!mainEditor.isDisposed) {
|
||||||
originalSettings.restore(editor)
|
HintManagerImpl.getInstanceImpl().hideAllHints()
|
||||||
editor.colorsScheme.setColor(EditorColors.CARET_COLOR, JumpMode.DISABLED.caretColor)
|
editorSettings.restore(mainEditor)
|
||||||
editor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
mainEditor.colorsScheme.setColor(EditorColors.CARET_COLOR, AbstractColorsScheme.INHERITED_COLOR_MARKER)
|
||||||
|
|
||||||
|
val focusedEditor = acceptedTag?.editor ?: mainEditor
|
||||||
|
focusedEditor.scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/main/kotlin/org/acejump/session/SessionActions.kt
Normal file
13
src/main/kotlin/org/acejump/session/SessionActions.kt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package org.acejump.session
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList
|
||||||
|
import org.acejump.search.SearchQuery
|
||||||
|
import org.acejump.view.TagMarker
|
||||||
|
|
||||||
|
internal interface SessionActions {
|
||||||
|
fun showHighlights(results: Map<Editor, IntList>, query: SearchQuery)
|
||||||
|
fun hideHighlights()
|
||||||
|
|
||||||
|
fun setTagMarkers(markers: Map<Editor, Collection<TagMarker>>)
|
||||||
|
}
|
@@ -16,7 +16,16 @@ object SessionManager {
|
|||||||
* Starts a new [Session], or returns an existing [Session] if the specified [Editor] already has one.
|
* Starts a new [Session], or returns an existing [Session] if the specified [Editor] already has one.
|
||||||
*/
|
*/
|
||||||
fun start(editor: Editor): Session {
|
fun start(editor: Editor): Session {
|
||||||
return sessions.getOrPut(editor) { cleanup(); Session(editor) }
|
return start(editor, listOf(editor))
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts a new multi-editor [Session], or returns an existing [Session] if the specified main [Editor] already has one.
|
||||||
|
* The [mainEditor] is used for typing the search query and tag.
|
||||||
|
* The [jumpEditors] are all editors that will be searched and tagged.
|
||||||
|
*/
|
||||||
|
fun start(mainEditor: Editor, jumpEditors: List<Editor>): Session {
|
||||||
|
return sessions.getOrPut(mainEditor) { cleanup(); Session(mainEditor, jumpEditors) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
72
src/main/kotlin/org/acejump/session/SessionState.kt
Normal file
72
src/main/kotlin/org/acejump/session/SessionState.kt
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package org.acejump.session
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.acejump.boundaries.Boundaries
|
||||||
|
import org.acejump.search.SearchProcessor
|
||||||
|
import org.acejump.search.Tagger
|
||||||
|
import org.acejump.search.TaggingResult
|
||||||
|
|
||||||
|
sealed interface SessionState {
|
||||||
|
fun type(char: Char): TypeResult
|
||||||
|
|
||||||
|
class WaitForKey internal constructor(
|
||||||
|
private val actions: SessionActions,
|
||||||
|
private val jumpEditors: List<Editor>,
|
||||||
|
private val defaultBoundary: Boundaries,
|
||||||
|
) : SessionState {
|
||||||
|
override fun type(char: Char): TypeResult {
|
||||||
|
val searchProcessor = SearchProcessor.fromString(jumpEditors, char.toString(), defaultBoundary)
|
||||||
|
|
||||||
|
return if (searchProcessor.isQueryFinished) {
|
||||||
|
TypeResult.ChangeState(SelectTag(actions, jumpEditors, searchProcessor))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TypeResult.ChangeState(RefineSearchQuery(actions, jumpEditors, searchProcessor))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RefineSearchQuery internal constructor(
|
||||||
|
private val actions: SessionActions,
|
||||||
|
private val jumpEditors: List<Editor>,
|
||||||
|
private val searchProcessor: SearchProcessor,
|
||||||
|
) : SessionState {
|
||||||
|
init {
|
||||||
|
actions.showHighlights(searchProcessor.resultsCopy, searchProcessor.query)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun type(char: Char): TypeResult {
|
||||||
|
return if (searchProcessor.refineQuery(char)) {
|
||||||
|
actions.hideHighlights()
|
||||||
|
TypeResult.ChangeState(SelectTag(actions, jumpEditors, searchProcessor))
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actions.showHighlights(searchProcessor.resultsCopy, searchProcessor.query)
|
||||||
|
TypeResult.Nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectTag internal constructor(
|
||||||
|
private val actions: SessionActions,
|
||||||
|
jumpEditors: List<Editor>,
|
||||||
|
searchProcessor: SearchProcessor,
|
||||||
|
) : SessionState {
|
||||||
|
private val tagger = Tagger(jumpEditors, searchProcessor.resultsCopy)
|
||||||
|
|
||||||
|
init {
|
||||||
|
actions.setTagMarkers(tagger.markers)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun type(char: Char): TypeResult {
|
||||||
|
return when (val result = tagger.type(char)) {
|
||||||
|
is TaggingResult.Nothing -> TypeResult.Nothing
|
||||||
|
is TaggingResult.Accept -> TypeResult.AcceptTag(result.tag)
|
||||||
|
is TaggingResult.Mark -> {
|
||||||
|
actions.setTagMarkers(result.markers)
|
||||||
|
TypeResult.Nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
src/main/kotlin/org/acejump/session/TypeResult.kt
Normal file
12
src/main/kotlin/org/acejump/session/TypeResult.kt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package org.acejump.session
|
||||||
|
|
||||||
|
import org.acejump.modes.SessionMode
|
||||||
|
import org.acejump.search.Tag
|
||||||
|
|
||||||
|
sealed class TypeResult {
|
||||||
|
object Nothing : TypeResult()
|
||||||
|
class ChangeState(val state: SessionState) : TypeResult()
|
||||||
|
class ChangeMode(val mode: SessionMode) : TypeResult()
|
||||||
|
class AcceptTag(val tag: Tag) : TypeResult()
|
||||||
|
object EndSession : TypeResult()
|
||||||
|
}
|
@@ -1,130 +0,0 @@
|
|||||||
package org.acejump.view
|
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
|
||||||
import com.intellij.ui.ColorUtil
|
|
||||||
import com.intellij.ui.scale.JBUIScale
|
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
|
||||||
import org.acejump.config.AceConfig
|
|
||||||
import org.acejump.countMatchingCharacters
|
|
||||||
import org.acejump.immutableText
|
|
||||||
import java.awt.Color
|
|
||||||
import java.awt.Graphics2D
|
|
||||||
import java.awt.Point
|
|
||||||
import java.awt.Rectangle
|
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Describes a 1 or 2 character shortcut that points to a specific character in the editor.
|
|
||||||
*/
|
|
||||||
internal class Tag(
|
|
||||||
private val tag: String,
|
|
||||||
val offsetL: Int,
|
|
||||||
val offsetR: Int,
|
|
||||||
private val shiftR: Int,
|
|
||||||
private val hasSpaceRight: Boolean
|
|
||||||
) {
|
|
||||||
private val length = tag.length
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val ARC = 1
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a new tag, precomputing some information about the nearby characters to reduce rendering overhead. If the last typed
|
|
||||||
* character ([literalQueryText]) matches the first [tag] character, only the second [tag] character is displayed.
|
|
||||||
*/
|
|
||||||
fun create(editor: Editor, tag: String, offset: Int, literalQueryText: String?): Tag {
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val matching = literalQueryText?.let { chars.countMatchingCharacters(offset, it) } ?: 0
|
|
||||||
val hasSpaceRight = offset + 1 >= chars.length || chars[offset + 1].isWhitespace()
|
|
||||||
|
|
||||||
val displayedTag = if (literalQueryText != null && literalQueryText.last().equals(tag.first(), ignoreCase = true))
|
|
||||||
tag.drop(1).toUpperCase()
|
|
||||||
else
|
|
||||||
tag.toUpperCase()
|
|
||||||
|
|
||||||
return Tag(displayedTag, offset, offset + max(0, matching - 1), tag.length - displayedTag.length, hasSpaceRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the tag background.
|
|
||||||
*/
|
|
||||||
private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
|
|
||||||
g.color = color
|
|
||||||
g.fillRoundRect(rect.x, rect.y, rect.width, rect.height + 1, ARC, ARC)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the tag text.
|
|
||||||
*/
|
|
||||||
private fun drawForeground(g: Graphics2D, font: TagFont, point: Point, text: String) {
|
|
||||||
val x = point.x + 2
|
|
||||||
val y = point.y + font.baselineDistance
|
|
||||||
|
|
||||||
g.font = font.tagFont
|
|
||||||
|
|
||||||
if (!ColorUtil.isDark(AceConfig.tagForegroundColor)) {
|
|
||||||
g.color = Color(0F, 0F, 0F, 0.35F)
|
|
||||||
g.drawString(text, x + 1, y + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
g.color = AceConfig.tagForegroundColor
|
|
||||||
g.drawString(text, x, y)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the left-aligned offset is in the range. Use to cull tags outside visible range.
|
|
||||||
* Only the left offset is checked, because if the tag was right-aligned on the last index of the range, it would not be visible anyway.
|
|
||||||
*/
|
|
||||||
fun isOffsetInRange(range: IntRange): Boolean {
|
|
||||||
return offsetL in range
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Paints the tag, taking into consideration visual space around characters in the editor, as well as all other previously painted tags.
|
|
||||||
* Returns a rectangle indicating the area where the tag was rendered, or null if the tag could not be rendered due to overlap.
|
|
||||||
*/
|
|
||||||
fun paint(g: Graphics2D, editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: MutableList<Rectangle>): Rectangle? {
|
|
||||||
val rect = alignTag(editor, cache, font, occupied) ?: return null
|
|
||||||
|
|
||||||
drawHighlight(g, rect, AceConfig.tagBackgroundColor)
|
|
||||||
drawForeground(g, font, rect.location, tag)
|
|
||||||
|
|
||||||
occupied.add(JBUIScale.scale(2).let { Rectangle(rect.x - it, rect.y, rect.width + (2 * it), rect.height) })
|
|
||||||
return rect
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? {
|
|
||||||
val boundaries = StandardBoundaries.VISIBLE_ON_SCREEN
|
|
||||||
|
|
||||||
if (hasSpaceRight || offsetL == 0 || editor.immutableText[offsetL - 1].let { it == '\n' || it == '\r' }) {
|
|
||||||
val rectR = createRightAlignedTagRect(editor, cache, font)
|
|
||||||
return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) && occupied.none(rectR::intersects) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val rectL = createLeftAlignedTagRect(editor, cache, font)
|
|
||||||
if (occupied.none(rectL::intersects)) {
|
|
||||||
return rectL.takeIf { boundaries.isOffsetInside(editor, offsetL, cache) }
|
|
||||||
}
|
|
||||||
|
|
||||||
val rectR = createRightAlignedTagRect(editor, cache, font)
|
|
||||||
if (occupied.none(rectR::intersects)) {
|
|
||||||
return rectR.takeIf { boundaries.isOffsetInside(editor, offsetR, cache) }
|
|
||||||
}
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createRightAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
|
|
||||||
val pos = cache.offsetToXY(editor, offsetR)
|
|
||||||
val shift = font.editorFontMetrics.charWidth(editor.immutableText[offsetR]) + (font.tagCharWidth * shiftR)
|
|
||||||
return Rectangle(pos.x + shift, pos.y, (font.tagCharWidth * length) + 4, font.lineHeight)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createLeftAlignedTagRect(editor: Editor, cache: EditorOffsetCache, font: TagFont): Rectangle {
|
|
||||||
val pos = cache.offsetToXY(editor, offsetL)
|
|
||||||
val shift = -(font.tagCharWidth * length)
|
|
||||||
return Rectangle(pos.x + shift - 4, pos.y, (font.tagCharWidth * length) + 4, font.lineHeight)
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,8 +2,7 @@ package org.acejump.view
|
|||||||
|
|
||||||
import com.intellij.openapi.application.ApplicationInfo
|
import com.intellij.openapi.application.ApplicationInfo
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.event.CaretEvent
|
import com.intellij.ui.ColorUtil
|
||||||
import com.intellij.openapi.editor.event.CaretListener
|
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
import org.acejump.boundaries.EditorOffsetCache
|
||||||
import org.acejump.boundaries.StandardBoundaries
|
import org.acejump.boundaries.StandardBoundaries
|
||||||
import java.awt.Graphics
|
import java.awt.Graphics
|
||||||
@@ -16,8 +15,9 @@ import javax.swing.SwingUtilities
|
|||||||
/**
|
/**
|
||||||
* Holds all active tag markers and renders them on top of the editor.
|
* Holds all active tag markers and renders them on top of the editor.
|
||||||
*/
|
*/
|
||||||
internal class TagCanvas(private val editor: Editor) : JComponent(), CaretListener {
|
internal class TagCanvas(private val editor: Editor) : JComponent() {
|
||||||
private var markers: List<Tag>? = null
|
private var markers: Collection<TagMarker> = emptyList()
|
||||||
|
private var visible = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val contentComponent = editor.contentComponent
|
val contentComponent = editor.contentComponent
|
||||||
@@ -27,63 +27,49 @@ internal class TagCanvas(private val editor: Editor) : JComponent(), CaretListen
|
|||||||
if (ApplicationInfo.getInstance().build.components.first() < 173) {
|
if (ApplicationInfo.getInstance().build.components.first() < 173) {
|
||||||
SwingUtilities.convertPoint(this, location, editor.component.rootPane).let { setLocation(-it.x, -it.y) }
|
SwingUtilities.convertPoint(this, location, editor.component.rootPane).let { setLocation(-it.x, -it.y) }
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.caretModel.addCaretListener(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbind() {
|
fun unbind() {
|
||||||
markers = null
|
|
||||||
editor.contentComponent.remove(this)
|
editor.contentComponent.remove(this)
|
||||||
editor.caretModel.removeCaretListener(this)
|
editor.contentComponent.repaint()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
fun setMarkers(markers: Collection<TagMarker>) {
|
||||||
* Ensures that all tags and the outline around the selected tag are repainted. It should not be necessary to repaint the entire tag
|
|
||||||
* canvas, but the cost of repainting visible tags is negligible.
|
|
||||||
*/
|
|
||||||
override fun caretPositionChanged(event: CaretEvent) {
|
|
||||||
repaint()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setMarkers(markers: List<Tag>) {
|
|
||||||
this.markers = markers
|
this.markers = markers
|
||||||
|
this.visible = true
|
||||||
repaint()
|
repaint()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeMarkers() {
|
fun removeMarkers() {
|
||||||
this.markers = emptyList()
|
this.markers = emptyList()
|
||||||
}
|
this.visible = false
|
||||||
|
repaint()
|
||||||
override fun paint(g: Graphics) {
|
|
||||||
if (!markers.isNullOrEmpty()) {
|
|
||||||
super.paint(g)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun paintChildren(g: Graphics) {
|
override fun paintChildren(g: Graphics) {
|
||||||
super.paintChildren(g)
|
super.paintChildren(g)
|
||||||
|
|
||||||
val markers = markers ?: return
|
if (!visible) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
g.color = ColorUtil.withAlpha(editor.colorsScheme.defaultBackground, 0.6)
|
||||||
|
g.fillRect(0, 0, width - 1, height - 1)
|
||||||
|
|
||||||
|
if (markers.isEmpty()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
(g as Graphics2D).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||||
|
|
||||||
val font = TagFont(editor)
|
val font = TagFont(editor)
|
||||||
|
|
||||||
val cache = EditorOffsetCache.new()
|
val cache = EditorOffsetCache.new()
|
||||||
val viewRange = StandardBoundaries.VISIBLE_ON_SCREEN.getOffsetRange(editor, cache)
|
val viewRange = StandardBoundaries.VISIBLE_ON_SCREEN.getOffsetRange(editor, cache)
|
||||||
val occupied = mutableListOf<Rectangle>()
|
val occupied = mutableListOf<Rectangle>()
|
||||||
|
|
||||||
(g as Graphics2D).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
|
||||||
|
|
||||||
// If there is a tag at the caret location, prioritize its rendering over all other tags. This is helpful for seeing which tag is
|
|
||||||
// currently selected while navigating highly clustered tags, although it does end up rearranging nearby tags which can be confusing.
|
|
||||||
|
|
||||||
// TODO instead of immediately painting, we could calculate the layout of everything first, and then remove tags that interfere with
|
|
||||||
// the caret tag to avoid changing the alignment of the caret tag
|
|
||||||
|
|
||||||
val caretOffset = editor.caretModel.offset
|
|
||||||
val caretMarker = markers.find { it.offsetL == caretOffset || it.offsetR == caretOffset }
|
|
||||||
caretMarker?.paint(g, editor, cache, font, occupied)
|
|
||||||
|
|
||||||
for (marker in markers) {
|
for (marker in markers) {
|
||||||
if (marker.isOffsetInRange(viewRange) && marker !== caretMarker) {
|
if (marker.offset in viewRange) {
|
||||||
marker.paint(g, editor, cache, font, occupied)
|
marker.paint(g, editor, cache, font, occupied)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -2,17 +2,18 @@ package org.acejump.view
|
|||||||
|
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.colors.EditorFontType
|
import com.intellij.openapi.editor.colors.EditorFontType
|
||||||
|
import org.acejump.config.AceConfig
|
||||||
import java.awt.Font
|
import java.awt.Font
|
||||||
import java.awt.FontMetrics
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores font metrics for aligning and rendering [Tag]s.
|
* Stores font metrics for aligning and rendering [TagMarker]s.
|
||||||
*/
|
*/
|
||||||
internal class TagFont(editor: Editor) {
|
internal class TagFont(editor: Editor) {
|
||||||
val tagFont: Font = editor.colorsScheme.getFont(EditorFontType.BOLD)
|
val tagFont: Font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
|
||||||
val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W')
|
val tagCharWidth = editor.component.getFontMetrics(tagFont).charWidth('W')
|
||||||
|
|
||||||
val editorFontMetrics: FontMetrics = editor.component.getFontMetrics(editor.colorsScheme.getFont(EditorFontType.PLAIN))
|
val foregroundColor = AceConfig.tagForegroundColor
|
||||||
|
|
||||||
val lineHeight = editor.lineHeight
|
val lineHeight = editor.lineHeight
|
||||||
val baselineDistance = editor.ascent
|
val baselineDistance = editor.ascent
|
||||||
}
|
}
|
||||||
|
73
src/main/kotlin/org/acejump/view/TagMarker.kt
Normal file
73
src/main/kotlin/org/acejump/view/TagMarker.kt
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package org.acejump.view
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.openapi.util.SystemInfo
|
||||||
|
import org.acejump.boundaries.EditorOffsetCache
|
||||||
|
import java.awt.Color
|
||||||
|
import java.awt.Graphics2D
|
||||||
|
import java.awt.Point
|
||||||
|
import java.awt.Rectangle
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes a 1 or 2 character shortcut that points to a specific character in the editor.
|
||||||
|
*/
|
||||||
|
internal class TagMarker(
|
||||||
|
private val tag: String,
|
||||||
|
val offset: Int
|
||||||
|
) {
|
||||||
|
private val length = tag.length
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* TODO This might be due to DPI settings.
|
||||||
|
*/
|
||||||
|
private val HIGHLIGHT_OFFSET = if (SystemInfo.isMac) -0.5 else 0.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new tag, precomputing some information about the nearby characters to reduce rendering overhead. If the last typed
|
||||||
|
* character ([typedTag]) matches the first [tag] character, only the second [tag] character is displayed.
|
||||||
|
*/
|
||||||
|
fun create(tag: String, offset: Int, typedTag: String): TagMarker {
|
||||||
|
return TagMarker(tag.drop(typedTag.length), offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the tag background.
|
||||||
|
*/
|
||||||
|
private fun drawHighlight(g: Graphics2D, rect: Rectangle, color: Color) {
|
||||||
|
g.color = color
|
||||||
|
g.translate(0.0, HIGHLIGHT_OFFSET)
|
||||||
|
g.fillRect(rect.x, rect.y, rect.width, rect.height + 1)
|
||||||
|
g.translate(0.0, -HIGHLIGHT_OFFSET)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the tag text.
|
||||||
|
*/
|
||||||
|
private fun drawForeground(g: Graphics2D, font: TagFont, point: Point, text: String) {
|
||||||
|
g.color = font.foregroundColor
|
||||||
|
g.font = font.tagFont
|
||||||
|
g.drawString(text, point.x, point.y + font.baselineDistance)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Paints the tag, taking into consideration visual space around characters in the editor, as well as all other previously painted tags.
|
||||||
|
* Returns a rectangle indicating the area where the tag was rendered, or null if the tag could not be rendered due to overlap.
|
||||||
|
*/
|
||||||
|
fun paint(g: Graphics2D, editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: MutableList<Rectangle>): Rectangle? {
|
||||||
|
val rect = alignTag(editor, cache, font, occupied) ?: return null
|
||||||
|
|
||||||
|
drawHighlight(g, rect, editor.colorsScheme.defaultBackground)
|
||||||
|
drawForeground(g, font, rect.location, tag)
|
||||||
|
|
||||||
|
occupied.add(rect)
|
||||||
|
return rect
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun alignTag(editor: Editor, cache: EditorOffsetCache, font: TagFont, occupied: List<Rectangle>): Rectangle? {
|
||||||
|
val pos = cache.offsetToXY(editor, offset)
|
||||||
|
val rect = Rectangle(pos.x, pos.y, font.tagCharWidth * length, font.lineHeight)
|
||||||
|
return rect.takeIf { occupied.none(it::intersects) }
|
||||||
|
}
|
||||||
|
}
|
@@ -6,71 +6,73 @@ import com.intellij.openapi.editor.markup.CustomHighlighterRenderer
|
|||||||
import com.intellij.openapi.editor.markup.HighlighterLayer
|
import com.intellij.openapi.editor.markup.HighlighterLayer
|
||||||
import com.intellij.openapi.editor.markup.HighlighterTargetArea
|
import com.intellij.openapi.editor.markup.HighlighterTargetArea
|
||||||
import com.intellij.openapi.editor.markup.RangeHighlighter
|
import com.intellij.openapi.editor.markup.RangeHighlighter
|
||||||
import com.intellij.util.ui.JBUI
|
import com.intellij.ui.ColorUtil
|
||||||
import it.unimi.dsi.fastutil.ints.IntList
|
import it.unimi.dsi.fastutil.ints.IntList
|
||||||
import org.acejump.boundaries.EditorOffsetCache
|
import org.acejump.boundaries.EditorOffsetCache
|
||||||
import org.acejump.config.AceConfig
|
import org.acejump.config.AceConfig
|
||||||
import org.acejump.immutableText
|
import org.acejump.immutableText
|
||||||
import org.acejump.input.JumpMode
|
|
||||||
import org.acejump.isWordPart
|
|
||||||
import org.acejump.search.SearchQuery
|
import org.acejump.search.SearchQuery
|
||||||
import org.acejump.wordEnd
|
import java.awt.Color
|
||||||
import org.acejump.wordStart
|
|
||||||
import java.awt.Graphics
|
import java.awt.Graphics
|
||||||
import kotlin.math.max
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders highlights for search occurrences.
|
* Renders highlights for search occurrences.
|
||||||
*/
|
*/
|
||||||
internal class TextHighlighter(private val editor: Editor) {
|
internal class TextHighlighter {
|
||||||
private companion object {
|
private var previousHighlights = mutableMapOf<Editor, Array<RangeHighlighter>>()
|
||||||
private const val LAYER = HighlighterLayer.LAST + 1
|
|
||||||
}
|
|
||||||
|
|
||||||
private var previousHighlights: Array<RangeHighlighter>? = null
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all current highlights and re-creates them from scratch. Must be called whenever any of the method parameters change.
|
* Removes all current highlights and re-creates them from scratch. Must be called whenever any of the method parameters change.
|
||||||
*/
|
*/
|
||||||
fun render(offsets: IntList, query: SearchQuery, jumpMode: JumpMode) {
|
fun renderOccurrences(results: Map<Editor, IntList>, query: SearchQuery) {
|
||||||
val markup = editor.markupModel
|
render(results, when (query) {
|
||||||
val chars = editor.immutableText
|
is SearchQuery.RegularExpression -> RegexRenderer
|
||||||
|
else -> SearchedWordRenderer
|
||||||
|
}, query::getHighlightLength)
|
||||||
|
}
|
||||||
|
|
||||||
val renderer = when {
|
private inline fun render(results: Map<Editor, IntList>, renderer: CustomHighlighterRenderer, getHighlightLength: (CharSequence, Int) -> Int) {
|
||||||
query is SearchQuery.RegularExpression -> RegexRenderer
|
for ((editor, offsets) in results) {
|
||||||
jumpMode === JumpMode.TARGET -> SearchedWordWithOutlineRenderer
|
val highlights = previousHighlights[editor]
|
||||||
else -> SearchedWordRenderer
|
|
||||||
}
|
|
||||||
|
|
||||||
val modifications = (previousHighlights?.size ?: 0) + offsets.size
|
val markup = editor.markupModel
|
||||||
val enableBulkEditing = modifications > 1000
|
val document = editor.document
|
||||||
|
val chars = editor.immutableText
|
||||||
|
|
||||||
val document = editor.document
|
val modifications = (highlights?.size ?: 0) + offsets.size
|
||||||
|
val enableBulkEditing = modifications > 1000
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (enableBulkEditing) {
|
if (enableBulkEditing) {
|
||||||
document.isInBulkUpdate = true
|
document.isInBulkUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
previousHighlights?.forEach(markup::removeHighlighter)
|
highlights?.forEach(markup::removeHighlighter)
|
||||||
previousHighlights = Array(offsets.size) { index ->
|
previousHighlights[editor] = Array(offsets.size) { index ->
|
||||||
val start = offsets.getInt(index)
|
val start = offsets.getInt(index)
|
||||||
val end = start + query.getHighlightLength(chars, start)
|
val end = start + getHighlightLength(chars, start)
|
||||||
|
|
||||||
markup.addRangeHighlighter(start, end, LAYER, null, HighlighterTargetArea.EXACT_RANGE).apply {
|
markup.addRangeHighlighter(start, end, LAYER, null, HighlighterTargetArea.EXACT_RANGE).apply {
|
||||||
customRenderer = renderer
|
customRenderer = renderer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (enableBulkEditing) {
|
||||||
|
document.isInBulkUpdate = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
}
|
||||||
if (enableBulkEditing) {
|
|
||||||
document.isInBulkUpdate = false
|
for (editor in previousHighlights.keys.toList()) {
|
||||||
|
if (!results.containsKey(editor)) {
|
||||||
|
previousHighlights.remove(editor)?.forEach(editor.markupModel::removeHighlighter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
editor.markupModel.removeAllHighlighters()
|
previousHighlights.keys.forEach { it.markupModel.removeAllHighlighters() }
|
||||||
previousHighlights = null
|
previousHighlights.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,43 +80,7 @@ internal class TextHighlighter(private val editor: Editor) {
|
|||||||
*/
|
*/
|
||||||
private object SearchedWordRenderer : CustomHighlighterRenderer {
|
private object SearchedWordRenderer : CustomHighlighterRenderer {
|
||||||
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
|
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
|
||||||
drawFilled(g, editor, highlighter.startOffset, highlighter.endOffset)
|
drawFilled(g, editor, highlighter.startOffset, highlighter.endOffset, AceConfig.searchHighlightColor)
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawFilled(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
|
|
||||||
val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
|
|
||||||
val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
|
|
||||||
|
|
||||||
g.color = AceConfig.textHighlightColor
|
|
||||||
g.fillRect(start.x, start.y + 1, end.x - start.x, editor.lineHeight - 1)
|
|
||||||
|
|
||||||
g.color = AceConfig.tagBackgroundColor
|
|
||||||
g.drawRect(start.x, start.y, end.x - start.x, editor.lineHeight)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders a filled highlight in the background of a searched text occurrence, as well as an outline indicating the range of characters
|
|
||||||
* that will be selected by [JumpMode.TARGET].
|
|
||||||
*/
|
|
||||||
private object SearchedWordWithOutlineRenderer : CustomHighlighterRenderer {
|
|
||||||
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
|
|
||||||
SearchedWordRenderer.paint(editor, highlighter, g)
|
|
||||||
|
|
||||||
val chars = editor.immutableText
|
|
||||||
val startOffset = highlighter.startOffset
|
|
||||||
|
|
||||||
if (chars.getOrNull(startOffset)?.isWordPart == true) {
|
|
||||||
drawOutline(g, editor, chars.wordStart(startOffset), chars.wordEnd(startOffset) + 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawOutline(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int) {
|
|
||||||
val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
|
|
||||||
val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
|
|
||||||
|
|
||||||
g.color = AceConfig.targetModeColor
|
|
||||||
g.drawRect(max(0, start.x - JBUI.scale(1)), start.y, end.x - start.x + JBUI.scale(2), editor.lineHeight)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,19 +89,34 @@ internal class TextHighlighter(private val editor: Editor) {
|
|||||||
*/
|
*/
|
||||||
private object RegexRenderer : CustomHighlighterRenderer {
|
private object RegexRenderer : CustomHighlighterRenderer {
|
||||||
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
|
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
|
||||||
drawSingle(g, editor, highlighter.startOffset)
|
drawSingle(g, editor, highlighter.startOffset, AceConfig.searchHighlightColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
private const val LAYER = HighlighterLayer.LAST + 1
|
||||||
|
|
||||||
|
private fun drawFilled(g: Graphics, editor: Editor, startOffset: Int, endOffset: Int, color: Color) {
|
||||||
|
val start = EditorOffsetCache.Uncached.offsetToXY(editor, startOffset)
|
||||||
|
val end = EditorOffsetCache.Uncached.offsetToXY(editor, endOffset)
|
||||||
|
|
||||||
|
g.color = ColorUtil.withAlpha(AceConfig.searchHighlightColor, 0.2)
|
||||||
|
g.fillRect(start.x, start.y + 1, end.x - start.x, editor.lineHeight - 1)
|
||||||
|
|
||||||
|
g.color = color
|
||||||
|
g.drawRect(start.x, start.y, end.x - start.x, editor.lineHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawSingle(g: Graphics, editor: Editor, offset: Int) {
|
private fun drawSingle(g: Graphics, editor: Editor, offset: Int, color: Color) {
|
||||||
val pos = EditorOffsetCache.Uncached.offsetToXY(editor, offset)
|
val pos = EditorOffsetCache.Uncached.offsetToXY(editor, offset)
|
||||||
val char = editor.immutableText.getOrNull(offset)?.takeUnless { it == '\n' || it == '\t' } ?: ' '
|
val char = editor.immutableText.getOrNull(offset)?.takeUnless { it == '\n' || it == '\t' } ?: ' '
|
||||||
val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
|
val font = editor.colorsScheme.getFont(EditorFontType.PLAIN)
|
||||||
val lastCharWidth = editor.component.getFontMetrics(font).charWidth(char)
|
val lastCharWidth = editor.component.getFontMetrics(font).charWidth(char)
|
||||||
|
|
||||||
g.color = AceConfig.textHighlightColor
|
g.color = ColorUtil.withAlpha(AceConfig.searchHighlightColor, 0.2)
|
||||||
g.fillRect(pos.x, pos.y + 1, lastCharWidth, editor.lineHeight - 1)
|
g.fillRect(pos.x, pos.y + 1, lastCharWidth, editor.lineHeight - 1)
|
||||||
|
|
||||||
g.color = AceConfig.tagBackgroundColor
|
g.color = color
|
||||||
g.drawRect(pos.x, pos.y, lastCharWidth, editor.lineHeight)
|
g.drawRect(pos.x, pos.y, lastCharWidth, editor.lineHeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<idea-plugin url="https://github.com/acejump/AceJump">
|
<idea-plugin>
|
||||||
<name>AceJump</name>
|
<name>AceJump</name>
|
||||||
<id>AceJump</id>
|
<id>AceJump-chylex</id>
|
||||||
|
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
AceJump allows you to quickly navigate the caret to any position visible in the editor.
|
AceJump allows you to quickly navigate the caret to any position visible in the editor.
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
</description>
|
</description>
|
||||||
|
|
||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
|
<depends>IdeaVIM</depends>
|
||||||
|
|
||||||
<category>Navigation</category>
|
<category>Navigation</category>
|
||||||
<vendor url="https://github.com/acejump/AceJump">AceJump</vendor>
|
<vendor url="https://github.com/acejump/AceJump">AceJump</vendor>
|
||||||
@@ -23,73 +24,28 @@
|
|||||||
implementationClass="org.acejump.action.AceEditorAction$Reset"/>
|
implementationClass="org.acejump.action.AceEditorAction$Reset"/>
|
||||||
<editorActionHandler action="EditorBackSpace" order="first"
|
<editorActionHandler action="EditorBackSpace" order="first"
|
||||||
implementationClass="org.acejump.action.AceEditorAction$ClearSearch"/>
|
implementationClass="org.acejump.action.AceEditorAction$ClearSearch"/>
|
||||||
<editorActionHandler action="EditorStartNewLine" order="first"
|
<editorActionHandler action="EditorEnter" order="first, before terminalEnter"
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SelectBackward"/>
|
implementationClass="org.acejump.action.AceEditorAction$TagImmediately"/>
|
||||||
<editorActionHandler action="EditorEnter" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SelectForward"/>
|
|
||||||
<editorActionHandler action="EditorUp" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SearchLineStarts"/>
|
|
||||||
<editorActionHandler action="EditorLeft" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SearchLineIndents"/>
|
|
||||||
<editorActionHandler action="EditorLineStart" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SearchLineIndents"/>
|
|
||||||
<editorActionHandler action="EditorRight" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
|
|
||||||
<editorActionHandler action="EditorLineEnd" order="first"
|
|
||||||
implementationClass="org.acejump.action.AceEditorAction$SearchLineEnds"/>
|
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
<actions>
|
<actions>
|
||||||
<action id="AceAction"
|
<action id="AceVimAction_JumpAllEditors" class="org.acejump.action.AceVimAction$JumpAllEditors" text="AceJump Vim - Jump All Editors" />
|
||||||
class="org.acejump.action.AceAction$ActivateOrCycleMode"
|
<action id="AceVimAction_JumpAllEditors_GoToDeclaration" class="org.acejump.action.AceVimAction$JumpAllEditorsGoToDeclaration" text="AceJump Vim - Jump All Editors - Go To Declaration" />
|
||||||
text="Activate / Cycle AceJump Mode">
|
<action id="AceVimAction_JumpForward" class="org.acejump.action.AceVimAction$JumpForward" text="AceJump Vim - Jump Forward" />
|
||||||
<keyboard-shortcut keymap="Mac OS X" first-keystroke="ctrl SEMICOLON"/>
|
<action id="AceVimAction_JumpBackward" class="org.acejump.action.AceVimAction$JumpBackward" text="AceJump Vim - Jump Backward" />
|
||||||
<keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="ctrl SEMICOLON"/>
|
<action id="AceVimAction_JumpTillForward" class="org.acejump.action.AceVimAction$JumpTillForward" text="AceJump Vim - Jump Till Forward" />
|
||||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl SEMICOLON"/>
|
<action id="AceVimAction_JumpTillBackward" class="org.acejump.action.AceVimAction$JumpTillBackward" text="AceJump Vim - Jump Till Backward" />
|
||||||
</action>
|
<action id="AceVimAction_JumpOnLineForward" class="org.acejump.action.AceVimAction$JumpOnLineForward" text="AceJump Vim - Jump On Line Forward" />
|
||||||
<action id="AceReverseAction"
|
<action id="AceVimAction_JumpOnLineBackward" class="org.acejump.action.AceVimAction$JumpOnLineBackward" text="AceJump Vim - Jump On Line Backward" />
|
||||||
class="org.acejump.action.AceAction$ActivateOrReverseCycleMode"
|
<action id="AceVimAction_JumpLineIndentsForward" class="org.acejump.action.AceVimAction$JumpLineIndentsForward" text="AceJump Vim - Jump Line Indents Forward" />
|
||||||
text="Activate / Reverse Cycle AceJump Mode"/>
|
<action id="AceVimAction_JumpLineIndentsBackward" class="org.acejump.action.AceVimAction$JumpLineIndentsBackward" text="AceJump Vim - Jump Line Indents Backward" />
|
||||||
<action id="AceWordStartAction"
|
<action id="AceVimAction_JumpLWordForward" class="org.acejump.action.AceVimAction$JumpLWordForward" text="AceJump Vim - Jump LWord Forward" />
|
||||||
class="org.acejump.action.AceAction$ToggleJumpMode"
|
<action id="AceVimAction_JumpUWordForward" class="org.acejump.action.AceVimAction$JumpUWordForward" text="AceJump Vim - Jump UWord Forward" />
|
||||||
text="Start AceJump in Jump Mode"/>
|
<action id="AceVimAction_JumpLWordBackward" class="org.acejump.action.AceVimAction$JumpLWordBackward" text="AceJump Vim - Jump LWord Backward" />
|
||||||
<action id="AceWordEndAction"
|
<action id="AceVimAction_JumpUWordBackward" class="org.acejump.action.AceVimAction$JumpUWordBackward" text="AceJump Vim - Jump UWord Backward" />
|
||||||
class="org.acejump.action.AceAction$ToggleJumpEndMode"
|
<action id="AceVimAction_JumpLWordEndForward" class="org.acejump.action.AceVimAction$JumpLWordEndForward" text="AceJump Vim - Jump LWord End Forward" />
|
||||||
text="Start AceJump in Jump End Mode"/>
|
<action id="AceVimAction_JumpUWordEndForward" class="org.acejump.action.AceVimAction$JumpUWordEndForward" text="AceJump Vim - Jump UWord End Forward" />
|
||||||
<action id="AceTargetAction"
|
<action id="AceVimAction_JumpLWordEndBackward" class="org.acejump.action.AceVimAction$JumpLWordEndBackward" text="AceJump Vim - Jump LWord End Backward" />
|
||||||
class="org.acejump.action.AceAction$ToggleTargetMode"
|
<action id="AceVimAction_JumpUWordEndBackward" class="org.acejump.action.AceVimAction$JumpUWordEndBackward" text="AceJump Vim - Jump UWord End Backward" />
|
||||||
text="Start AceJump in Target Mode">
|
|
||||||
<keyboard-shortcut keymap="Mac OS X" first-keystroke="ctrl alt SEMICOLON"/>
|
|
||||||
<keyboard-shortcut keymap="Mac OS X 10.5+" first-keystroke="ctrl alt SEMICOLON"/>
|
|
||||||
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt SEMICOLON"/>
|
|
||||||
</action>
|
|
||||||
<action id="AceDeclarationAction"
|
|
||||||
class="org.acejump.action.AceAction$ToggleDeclarationMode"
|
|
||||||
text="Start AceJump in Declaration Mode"/>
|
|
||||||
<action id="AceLineAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllLineMarksMode"
|
|
||||||
text="Start AceJump in All Line Marks Mode">
|
|
||||||
<keyboard-shortcut keymap="Mac OS X" first-keystroke="ctrl shift SEMICOLON"/>
|
|
||||||
<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="AceLineStartsAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllLineStartsMode"
|
|
||||||
text="Start AceJump in All Line Starts Mode"/>
|
|
||||||
<action id="AceLineEndsAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllLineEndsMode"
|
|
||||||
text="Start AceJump in All Line Ends Mode"/>
|
|
||||||
<action id="AceLineIndentsAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllLineIndentsMode"
|
|
||||||
text="Start AceJump in All Line Indents Mode"/>
|
|
||||||
<action id="AceWordAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllWordsMode"
|
|
||||||
text="Start AceJump in All Words Mode"/>
|
|
||||||
<action id="AceWordForwardAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllWordsForwardMode"
|
|
||||||
text="Start AceJump in All Words After Caret Mode"/>
|
|
||||||
<action id="AceWordBackwardsAction"
|
|
||||||
class="org.acejump.action.AceAction$StartAllWordsBackwardsMode"
|
|
||||||
text="Start AceJump in All Words Before Caret Mode"/>
|
|
||||||
</actions>
|
</actions>
|
||||||
</idea-plugin>
|
</idea-plugin>
|
||||||
|
@@ -1,115 +0,0 @@
|
|||||||
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_ENTER
|
|
||||||
import com.intellij.openapi.actionSystem.IdeActions.ACTION_EDITOR_START_NEW_LINE
|
|
||||||
import org.acejump.action.AceAction
|
|
||||||
import org.acejump.test.util.BaseTest
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Functional test cases and end-to-end performance tests.
|
|
||||||
*
|
|
||||||
* TODO: Add more structure to test cases, use test resources to define files.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class AceTest : BaseTest() {
|
|
||||||
fun `test that scanner finds all occurrences of single character`() =
|
|
||||||
assertEquals("test test test".search("t"), setOf(0, 3, 5, 8, 10, 13))
|
|
||||||
|
|
||||||
fun `test empty results for an absent query`() =
|
|
||||||
assertEmpty("test test test".search("best"))
|
|
||||||
|
|
||||||
fun `test sticky results on a query with extra characters`() =
|
|
||||||
assertEquals("test test test".search("testz"), setOf(0, 5, 10))
|
|
||||||
|
|
||||||
fun `test a query inside text with some variations`() =
|
|
||||||
assertEquals("abcd dabc cdab".search("cd"), setOf(2, 10))
|
|
||||||
|
|
||||||
fun `test a query containing a space character`() =
|
|
||||||
assertEquals("abcd dabc cdab".search("cd "), setOf(2))
|
|
||||||
|
|
||||||
fun `test a query containing a { character`() =
|
|
||||||
assertEquals("abcd{dabc cdab".search("cd{"), setOf(2))
|
|
||||||
|
|
||||||
fun `test that jumping to first occurrence succeeds`() {
|
|
||||||
"<caret>testing 1234".search("1")
|
|
||||||
|
|
||||||
takeAction(ACTION_EDITOR_ENTER)
|
|
||||||
|
|
||||||
myFixture.checkResult("testing <caret>1234")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test that jumping to second occurrence succeeds`() {
|
|
||||||
"<caret>testing 1234".search("ti")
|
|
||||||
|
|
||||||
takeAction(ACTION_EDITOR_ENTER)
|
|
||||||
|
|
||||||
myFixture.checkResult("tes<caret>ting 1234")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test that jumping to previous occurrence succeeds`() {
|
|
||||||
"te<caret>sting 1234".search("t")
|
|
||||||
|
|
||||||
takeAction(ACTION_EDITOR_START_NEW_LINE)
|
|
||||||
|
|
||||||
myFixture.checkResult("<caret>testing 1234")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test tag selection`() {
|
|
||||||
"<caret>testing 1234".search("g")
|
|
||||||
|
|
||||||
typeAndWaitForResults(session.tags[0].key)
|
|
||||||
|
|
||||||
myFixture.checkResult("testin<caret>g 1234")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test shift selection`() {
|
|
||||||
"<caret>testing 1234".search("4")
|
|
||||||
|
|
||||||
typeAndWaitForResults(session.tags[0].key.toUpperCase())
|
|
||||||
|
|
||||||
myFixture.checkResult("<selection>testing 123<caret></selection>4")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test words before caret action`() {
|
|
||||||
makeEditor("test words <caret> before caret is two")
|
|
||||||
|
|
||||||
takeAction(AceAction.StartAllWordsBackwardsMode)
|
|
||||||
|
|
||||||
assertEquals(2, session.tags.size)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test words after caret action`() {
|
|
||||||
makeEditor("test words <caret> after caret is four")
|
|
||||||
|
|
||||||
takeAction(AceAction.StartAllWordsForwardMode)
|
|
||||||
|
|
||||||
assertEquals(4, session.tags.size)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test word mode`() {
|
|
||||||
makeEditor("test word action")
|
|
||||||
|
|
||||||
takeAction(AceAction.StartAllWordsMode)
|
|
||||||
|
|
||||||
assertEquals(3, session.tags.size)
|
|
||||||
|
|
||||||
typeAndWaitForResults(session.tags[1].key)
|
|
||||||
|
|
||||||
myFixture.checkResult("test <caret>word action")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test target mode`() {
|
|
||||||
"<caret>test target action".search("target")
|
|
||||||
|
|
||||||
takeAction(AceAction.ToggleTargetMode)
|
|
||||||
typeAndWaitForResults(session.tags[0].key)
|
|
||||||
|
|
||||||
myFixture.checkResult("test <selection>target<caret></selection> action")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun `test line mode`() {
|
|
||||||
makeEditor(" test\n three\n lines\n")
|
|
||||||
|
|
||||||
takeAction(AceAction.StartAllLineMarksMode)
|
|
||||||
|
|
||||||
assertEquals(8, session.tags.size) // last empty line does not count
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +1,10 @@
|
|||||||
import org.acejump.action.AceAction
|
|
||||||
|
import org.acejump.action.AceVimAction
|
||||||
import org.acejump.test.util.BaseTest
|
import org.acejump.test.util.BaseTest
|
||||||
import org.junit.Ignore
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
import kotlin.system.measureTimeMillis
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
@Ignore
|
|
||||||
class LatencyTest : BaseTest() {
|
class LatencyTest : BaseTest() {
|
||||||
|
|
||||||
private fun `test tag latency`(editorText: String) {
|
private fun `test tag latency`(editorText: String) {
|
||||||
@@ -15,7 +14,7 @@ class LatencyTest : BaseTest() {
|
|||||||
|
|
||||||
for (query in chars) {
|
for (query in chars) {
|
||||||
makeEditor(editorText)
|
makeEditor(editorText)
|
||||||
myFixture.testAction(AceAction.ActivateOrCycleMode)
|
myFixture.testAction(AceVimAction.JumpAllEditors())
|
||||||
time += measureTimeMillis { typeAndWaitForResults("$query") }
|
time += measureTimeMillis { typeAndWaitForResults("$query") }
|
||||||
// TODO assert(Tagger.markers.isNotEmpty()) { "Should be tagged: $query" }
|
// TODO assert(Tagger.markers.isNotEmpty()) { "Should be tagged: $query" }
|
||||||
resetEditor()
|
resetEditor()
|
||||||
|
@@ -2,11 +2,12 @@ package org.acejump.test.util
|
|||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction
|
import com.intellij.openapi.actionSystem.AnAction
|
||||||
import com.intellij.openapi.actionSystem.IdeActions
|
import com.intellij.openapi.actionSystem.IdeActions
|
||||||
|
import com.intellij.openapi.editor.impl.EditorImpl
|
||||||
import com.intellij.openapi.fileTypes.PlainTextFileType
|
import com.intellij.openapi.fileTypes.PlainTextFileType
|
||||||
import com.intellij.psi.PsiFile
|
import com.intellij.psi.PsiFile
|
||||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||||
import com.intellij.util.ui.UIUtil
|
import com.intellij.util.ui.UIUtil
|
||||||
import org.acejump.action.AceAction
|
import org.acejump.action.AceVimAction
|
||||||
import org.acejump.session.SessionManager
|
import org.acejump.session.SessionManager
|
||||||
|
|
||||||
abstract class BaseTest : BasePlatformTestCase() {
|
abstract class BaseTest : BasePlatformTestCase() {
|
||||||
@@ -38,7 +39,9 @@ abstract class BaseTest : BasePlatformTestCase() {
|
|||||||
fun takeAction(action: AnAction) = myFixture.testAction(action)
|
fun takeAction(action: AnAction) = myFixture.testAction(action)
|
||||||
|
|
||||||
fun makeEditor(contents: String): PsiFile {
|
fun makeEditor(contents: String): PsiFile {
|
||||||
return myFixture.configureByText(PlainTextFileType.INSTANCE, contents)
|
val file = myFixture.configureByText(PlainTextFileType.INSTANCE, contents)
|
||||||
|
(myFixture.editor as EditorImpl).scrollPane.viewport.setSize(1000, 100)
|
||||||
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resetEditor() {
|
fun resetEditor() {
|
||||||
@@ -52,10 +55,10 @@ abstract class BaseTest : BasePlatformTestCase() {
|
|||||||
UIUtil.dispatchAllInvocationEvents()
|
UIUtil.dispatchAllInvocationEvents()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun String.executeQuery(query: String) {
|
private fun String.executeQuery(query: String) {
|
||||||
myFixture.run {
|
myFixture.run {
|
||||||
makeEditor(this@executeQuery)
|
makeEditor(this@executeQuery)
|
||||||
testAction(AceAction.ActivateOrCycleMode)
|
testAction(AceVimAction.JumpAllEditors())
|
||||||
typeAndWaitForResults(query)
|
typeAndWaitForResults(query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user