Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 14, 2019
1 parent 345383b commit 48d9c3b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/main/kotlin/org/acejump/control/Handler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object Handler : TypedActionHandler, Resettable {
}

private fun configureEditor() =
runAndWait {
runNow {
editor.run {
enabled = true
saveScroll()
Expand Down Expand Up @@ -99,7 +99,7 @@ object Handler : TypedActionHandler, Resettable {
}

fun redoFind() {
runAndWait {
runNow {
editor.run {
restoreCanvas()
bindCanvas()
Expand All @@ -119,7 +119,7 @@ object Handler : TypedActionHandler, Resettable {
editor.restoreSettings()
}

private fun Editor.restoreSettings() = runAndWait {
private fun Editor.restoreSettings() = runNow {
enabled = false
swapActionHandler()
uninstallKeyHandler()
Expand Down Expand Up @@ -151,12 +151,12 @@ object Handler : TypedActionHandler, Resettable {
EditorColorsManager.getInstance().globalScheme.getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES)
?.backgroundColor.let { Model.naturalHighlight = it }

private fun Editor.restoreCaret() = runAndWait {
private fun Editor.restoreCaret() = runNow {
settings.isBlinkCaret = Model.naturalBlink
settings.isBlockCursor = Model.naturalBlock
}

private fun Editor.restoreColors() = runAndWait {
private fun Editor.restoreColors() = runNow {
colorsScheme.run {
setAttributes(TEXT_SEARCH_RESULT_ATTRIBUTES,
getAttributes(TEXT_SEARCH_RESULT_ATTRIBUTES)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/acejump/label/Tagger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object Tagger : Resettable {
markAndMapTags().apply { if (isNotEmpty()) tagMap = this }

if (markers.isNotEmpty() && markers.noneInView && 1 < query.length)
runAndWait { Scroller.scroll() }
runNow { Scroller.scroll() }
}

private fun markAndMapTags(): Map<String, Int> {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/org/acejump/search/AceUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ operator fun CharSequence.get(i: Int, j: Int) = substring(i, j).toCharArray()
fun String.hasSpaceRight(i: Int) = length <= i + 1 || this[i + 1].isWhitespace()

@Deprecated("This is applied too broadly. Narrow down usages where necessary.")
fun runAndWait(t: () -> Unit) = ApplicationManager.getApplication().invokeAndWait(t)
fun runNow(t: () -> Unit) = ApplicationManager.getApplication().invokeAndWait(t)

@Deprecated("This is applied too broadly. Narrow down usages where necessary.")
fun runLater(t: () -> Unit) = ApplicationManager.getApplication().invokeLater(t)
Expand Down Expand Up @@ -95,7 +95,7 @@ fun Editor.isFirstCharacterOfLine(index: Int) =
*/

fun getFeasibleRegion(results: List<Int>, takeAtMost: Int = MAX_TAG_RESULTS) =
((viewBounds.first + viewBounds.last) / 2).let { middleOfScreen ->
(viewBounds.run { first + last } / 2).let { middleOfScreen ->
results.sortedBy { abs(middleOfScreen - it) }
.take(min(results.size, takeAtMost))
}.sorted().let { if (it.isNotEmpty()) it.first()..it.last() else null }
Expand All @@ -114,7 +114,7 @@ fun Editor.getView(): IntRange {
return startOffset..endOffset
}

fun Editor.selectRange(fromOffset: Int, toOffset: Int) = runAndWait {
fun Editor.selectRange(fromOffset: Int, toOffset: Int) = runNow {
selectionModel.removeSelection()
selectionModel.setSelection(fromOffset, toOffset)
caretModel.moveToOffset(toOffset)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/acejump/search/Jumper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object Jumper: Resettable {
}

private fun gotoSymbolAction() =
runAndWait {
runNow {
ActionManager.getInstance().tryToExecute(GotoDeclarationAction(),
ActionCommand.getInputEvent("NewFromTemplate"), null, null, true)
}
Expand Down

0 comments on commit 48d9c3b

Please sign in to comment.