xusoo / duplicate-lines-intellij-plugin

IntelliJ plugin for duplicating selected lines up or down
MIT License
2 stars 1 forks source link

Exception when activated in a read-only editor #3

Closed joshgold22 closed 5 years ago

joshgold22 commented 5 years ago

If you activate Duplicate in a read-only context (e.g., if you're looking at an earlier revision, or "annotate previous revision" and forget to switch back to the original editor), IntelliJ brings up a bug-report popup with the exception below.

Ideally I think the plug-in should behave just like typing: If you type in a read-only context, IntelliJ nomally brings up a little widget that says "File is read-only".

com.intellij.openapi.editor.ReadOnlyModificationException: Attempt to modify read-only document
    at com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:541)
    at DuplicateLines.duplicateDown(DuplicateLines.java:101)
    at DuplicateLines.duplicateLines(DuplicateLines.java:78)
    at DuplicateLines.lambda$null$0(DuplicateLines.java:37)
    at com.intellij.openapi.editor.impl.CaretModelImpl.lambda$runForEachCaret$3(CaretModelImpl.java:354)
    at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:453)
    at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:346)
    at com.intellij.openapi.editor.impl.CaretModelImpl.runForEachCaret(CaretModelImpl.java:336)
    at DuplicateLines.lambda$actionPerformed$1(DuplicateLines.java:37)
    at com.intellij.openapi.command.WriteCommandAction.lambda$runWriteCommandAction$5(WriteCommandAction.java:361)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$1.run(WriteCommandAction.java:124)
    at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
    at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:263)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1054)
    at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:262)
    at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:319)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
    at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:188)
    at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:321)
    at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:262)
    at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:244)
    at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.run(WriteCommandAction.java:126)
    at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:361)
    at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:353)
    at DuplicateLines.actionPerformed(DuplicateLines.java:36)
    at com.intellij.openapi.actionSystem.ex.ActionUtil$1.run(ActionUtil.java:261)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:278)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$1.performAction(IdeKeyEventDispatcher.java:622)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.lambda$processAction$2(IdeKeyEventDispatcher.java:671)
    at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:195)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.java:670)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.java:518)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.java:473)
    at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.java:223)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:653)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:373)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
xusoo commented 5 years ago

Good catch!

I just uploaded a new version, but it's still pending approval (Commit: 47fecf18bde042812a7e1f8d7d6997f62f097fde)

Thanks!