generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware): add InsertNewlineProcessor
Add InsertNewlineProcessor to handle inserting newlines in the editor. - Added InsertNewlineProcessor class to insert newlines at the cursor position in the editor. - Updated configuration file to include InsertNewlineProcessor implementation.
- Loading branch information
Showing
7 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/InsertNewlineProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.phodal.shirecore.middleware.builtin | ||
|
||
import com.intellij.execution.ui.ConsoleView | ||
import com.intellij.openapi.application.runWriteAction | ||
import com.intellij.openapi.command.WriteCommandAction | ||
import com.intellij.openapi.project.Project | ||
import com.phodal.shirecore.middleware.BuiltinPostHandler | ||
import com.phodal.shirecore.middleware.PostCodeHandleContext | ||
import com.phodal.shirecore.middleware.PostProcessor | ||
import com.phodal.shirecore.workerThread | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.launch | ||
|
||
class InsertNewlineProcessor : PostProcessor { | ||
override val processorName: String = BuiltinPostHandler.InsertNewline.handleName | ||
|
||
override fun isApplicable(context: PostCodeHandleContext): Boolean { | ||
return true | ||
} | ||
|
||
override fun execute(project: Project, context: PostCodeHandleContext, console: ConsoleView?): Any { | ||
val editor = context.editor ?: return "" | ||
|
||
CoroutineScope(workerThread).launch { | ||
WriteCommandAction.runWriteCommandAction(project) { | ||
// insert \n at cursor position | ||
editor.document.insertString(editor.caretModel.offset, "\n") | ||
} | ||
} | ||
|
||
return "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters