package osmedile.intellij.stringmanip.actions;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actions.TextComponentEditorAction;
import com.intellij.openapi.project.DumbAware;
import org.jetbrains.annotations.Nullable;
import osmedile.intellij.stringmanip.MyEditorWriteActionHandler;

public class SelectWordInDifferentHumpsModeAction extends TextComponentEditorAction implements DumbAware {

	protected SelectWordInDifferentHumpsModeAction() {
		super(new MyEditorWriteActionHandler<String>(SelectWordInDifferentHumpsModeAction.class) {
			@Override
			protected void executeWriteAction(Editor editor, DataContext dataContext, @Nullable String additionalParameter) {
				EditorSettings settings = editor.getSettings();
				boolean camelWords = settings.isCamelWords();
				try {
					settings.setCamelWords(!camelWords);
					EditorAction editorSelectWord = (EditorAction) ActionManager.getInstance().getAction("EditorSelectWord");
					editorSelectWord.getHandler().execute(editor, null, dataContext);
				} finally {
					settings.setCamelWords(camelWords);
				}
			}

			@Override
			protected void setLastAction() {
			}
		});
		setInjectedContext(true);
	}

}

@@ -97,16 +97,77 @@
 anager;%0A
+import com.intellij.openapi.actionSystem.ActionUpdateThread;%0A
 import c
@@ -212,16 +212,16 @@
 ontext;%0A
-
 import c
@@ -485,16 +485,58 @@
 bAware;%0A
+import org.jetbrains.annotations.NotNull;%0A
 import o
@@ -694,29 +694,16 @@
 extends 
-TextComponent
 EditorAc
@@ -1503,10 +1503,284 @@
 e);%0A%09%7D%0A%0A
+%09@Override%0A%09public final @NotNull ActionUpdateThread getActionUpdateThread() %7B%0A%09%09return ActionUpdateThread.BGT;%0A%09%7D%0A%0A%09@Override%0A%09protected @Nullable Editor getEditor(@NotNull DataContext dataContext) %7B%0A%09%09return TextComponentEditorAction.getEditorFromContext(dataContext);%0A%09%7D%0A
 %7D%0A

fix for: UnsupportedOperationException: TextComponentEditorAction is updated on EDT only and must not work in injected context according to: update SelectWordAtCaretAction action in BGT 21.10.2022 23:14 Gregory.Shrago*