Skip to content

Commit a530ff6

Browse files
committed
Activate content assist only when caret enters the viewer
Content assist is now activated only when the caret moves inside the Detail Pane, preventing interference with Expressions View and Variables Views and enhancing the overall user experience. Fixes : #2151
1 parent f48bab4 commit a530ff6

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/variables/details/DefaultDetailPane.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2019 IBM Corporation and others.
2+
* Copyright (c) 2006, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -82,6 +82,7 @@
8282
import org.eclipse.swt.custom.StyledText;
8383
import org.eclipse.swt.events.FocusAdapter;
8484
import org.eclipse.swt.events.FocusEvent;
85+
import org.eclipse.swt.events.FocusListener;
8586
import org.eclipse.swt.events.KeyEvent;
8687
import org.eclipse.swt.events.KeyListener;
8788
import org.eclipse.swt.events.MouseEvent;
@@ -591,18 +592,46 @@ public void focusLost(FocusEvent e) {
591592
* Creates the actions to add to the context menu
592593
*/
593594
private void createActions() {
594-
TextViewerAction textAction= new TextViewerAction(fSourceViewer, ISourceViewer.CONTENTASSIST_PROPOSALS);
595-
textAction.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
596-
textAction.configureAction(DetailMessages.DefaultDetailPane_Co_ntent_Assist_3, IInternalDebugCoreConstants.EMPTY_STRING,IInternalDebugCoreConstants.EMPTY_STRING);
597-
textAction.setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_ELCL_CONTENT_ASSIST));
598-
textAction.setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_DLCL_CONTENT_ASSIST));
599-
PlatformUI.getWorkbench().getHelpSystem().setHelp(textAction, IDebugHelpContextIds.DETAIL_PANE_CONTENT_ASSIST_ACTION);
600-
ActionHandler actionHandler = new ActionHandler(textAction);
601-
IHandlerService handlerService = getViewSite().getService(IHandlerService.class);
602-
fContentAssistActivation = handlerService.activateHandler(textAction.getActionDefinitionId(), actionHandler);
603-
setAction(DETAIL_CONTENT_ASSIST_ACTION, textAction);
604-
605-
textAction= new TextViewerAction(fSourceViewer, ITextOperationTarget.SELECT_ALL);
595+
TextViewerAction contAssistTextViewer = new TextViewerAction(fSourceViewer, ISourceViewer.CONTENTASSIST_PROPOSALS);
596+
597+
contAssistTextViewer.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
598+
contAssistTextViewer.configureAction(DetailMessages.DefaultDetailPane_Co_ntent_Assist_3,
599+
IInternalDebugCoreConstants.EMPTY_STRING, IInternalDebugCoreConstants.EMPTY_STRING);
600+
contAssistTextViewer.setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_ELCL_CONTENT_ASSIST));
601+
contAssistTextViewer.setDisabledImageDescriptor(
602+
DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_DLCL_CONTENT_ASSIST));
603+
PlatformUI.getWorkbench().getHelpSystem().setHelp(contAssistTextViewer,
604+
IDebugHelpContextIds.DETAIL_PANE_CONTENT_ASSIST_ACTION);
605+
ActionHandler actionHandler = new ActionHandler(contAssistTextViewer);
606+
setAction(DETAIL_CONTENT_ASSIST_ACTION, contAssistTextViewer);
607+
608+
StyledText text = fSourceViewer.getTextWidget();
609+
610+
text.addCaretListener(event -> {
611+
if (text.isFocusControl()) {
612+
if (fContentAssistActivation == null) {
613+
IHandlerService handlerService = getViewSite().getService(IHandlerService.class);
614+
fContentAssistActivation = handlerService.activateHandler(contAssistTextViewer.getActionDefinitionId(),
615+
actionHandler);
616+
}
617+
}
618+
});
619+
620+
text.addFocusListener(new FocusListener() {
621+
@Override
622+
public void focusLost(FocusEvent e) {
623+
if (fContentAssistActivation != null) {
624+
IHandlerService handlerService = getViewSite().getService(IHandlerService.class);
625+
handlerService.deactivateHandler(fContentAssistActivation);
626+
fContentAssistActivation = null;
627+
}
628+
}
629+
@Override
630+
public void focusGained(FocusEvent e) {
631+
}
632+
});
633+
634+
TextViewerAction textAction = new TextViewerAction(fSourceViewer, ITextOperationTarget.SELECT_ALL);
606635
textAction.configureAction(DetailMessages.DefaultDetailPane_Select__All_5, IInternalDebugCoreConstants.EMPTY_STRING,IInternalDebugCoreConstants.EMPTY_STRING);
607636
textAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_SELECT_ALL);
608637
PlatformUI.getWorkbench().getHelpSystem().setHelp(textAction, IDebugHelpContextIds.DETAIL_PANE_SELECT_ALL_ACTION);

0 commit comments

Comments
 (0)