mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
[Java. Code Formatting] Add better compatibility of CaretRestorationDecider for Java files
IDEA-351758 GitOrigin-RevId: 203fdafe497e21a92938a6ed908f818348cba8ae
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f6abeeb22f
commit
d522882314
@@ -2205,9 +2205,10 @@ f:com.intellij.codeInspection.util.RefEntityAlphabeticalComparator
|
||||
- s:getInstance():com.intellij.codeInspection.util.RefEntityAlphabeticalComparator
|
||||
*:com.intellij.formatting.CaretRestorationDecider
|
||||
- *sf:Companion:com.intellij.formatting.CaretRestorationDecider$Companion
|
||||
- s:forLanguage(com.intellij.lang.Language):com.intellij.formatting.CaretRestorationDecider
|
||||
- a:shouldRestoreCaret(com.intellij.openapi.editor.Document,com.intellij.openapi.editor.Editor,I):Z
|
||||
*f:com.intellij.formatting.CaretRestorationDecider$Companion
|
||||
- com.intellij.lang.LanguageExtension
|
||||
- f:forLanguage(com.intellij.lang.Language):com.intellij.formatting.CaretRestorationDecider
|
||||
a:com.intellij.ide.PlatformIdeService
|
||||
- <init>():V
|
||||
- createHyperlinkConsumer():java.util.function.BiConsumer
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.formatting
|
||||
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.lang.LanguageExtension
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.editor.Editor
|
||||
@@ -14,7 +15,7 @@ import org.jetbrains.annotations.ApiStatus
|
||||
@ApiStatus.Experimental
|
||||
interface CaretRestorationDecider {
|
||||
/**
|
||||
* Determines whether the caret position should be restored after formatting.
|
||||
* Determines whether the caret position should be restored after formatting. Should be invoked under read action.
|
||||
* @param document the document being formatted
|
||||
* @param editor the editor in which the document is being displayed
|
||||
* @param caretOffset offset in which the caret is located.
|
||||
@@ -23,5 +24,10 @@ interface CaretRestorationDecider {
|
||||
*/
|
||||
fun shouldRestoreCaret(document: Document, editor: Editor, caretOffset: Int): Boolean
|
||||
|
||||
companion object : LanguageExtension<CaretRestorationDecider>("com.intellij.formatting.caretRestorationDecider")
|
||||
companion object {
|
||||
private val EP_NAME = LanguageExtension<CaretRestorationDecider>("com.intellij.formatting.caretRestorationDecider")
|
||||
|
||||
@JvmStatic
|
||||
fun forLanguage(language: Language): CaretRestorationDecider? = EP_NAME.forLanguage(language)
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public final class CaretPositionKeeper {
|
||||
}
|
||||
|
||||
int caretOffset = getCaretOffset();
|
||||
CaretRestorationDecider decider = CaretRestorationDecider.Companion.forLanguage(language);
|
||||
CaretRestorationDecider decider = CaretRestorationDecider.forLanguage(language);
|
||||
|
||||
if (decider == null) {
|
||||
decider = DefaultCaretRestorationDecider.INSTANCE;
|
||||
|
||||
Reference in New Issue
Block a user