Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-5643. Add ability to select items in the quick fix window using keyboard #5761

Merged
merged 1 commit into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
*******************************************************************************/
package org.eclipse.che.ide.ui.popup;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.util.dom.Elements;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.event.dom.client.KeyCodes;
Expand Down Expand Up @@ -81,6 +83,7 @@ private void focusNext() {
if (current.getParentElement().isEqualNode(listElement)) {
final Element next = current.getNextElementSibling();
if (next != null) {
select(next);
next.focus();
} else {
focusFirst();
Expand All @@ -100,6 +103,7 @@ private void focusPrevious() {
if (current.getParentElement().isEqualNode(listElement)) {
final Element prev = current.getPreviousElementSibling();
if (prev != null) {
select(prev);
prev.focus();
} else {
focusLast();
Expand All @@ -114,17 +118,21 @@ private void focusPrevious() {
* Focus the first item in the list (if any).
*/
private void focusFirst() {
if (this.listElement.hasChildNodes()) {
this.listElement.getFirstElementChild().focus();
if (listElement.hasChildNodes()) {
Element firstElement = listElement.getFirstElementChild();
select(firstElement);
firstElement.focus();
}
}

/**
* Focus the last item in the list (if any).
*/
private void focusLast() {
if (this.listElement.hasChildNodes()) {
this.listElement.getLastElementChild().focus();
if (listElement.hasChildNodes()) {
Element lastElement = listElement.getLastElementChild();
select(lastElement);
lastElement.focus();
}
}

Expand All @@ -137,4 +145,34 @@ private void validateItem() {
this.popupWidget.validateItem(current);
}
}

private void select(Element elementToSelect) {
if (elementToSelect == null) {
return;
}

Element currentSelectedElement = getSelectedElement();
if (currentSelectedElement == null) {
elementToSelect.setAttribute("selected", "true");
return;
}

if (currentSelectedElement.isEqualNode(elementToSelect)) {
return;
}

currentSelectedElement.removeAttribute("selected");
elementToSelect.setAttribute("selected", "true");
}

/**
* Returns current selected element when we have an item in focus or {@code null} otherwise
*
* @return current selected element or {@code null} when we have no any items in focus
*/
@Nullable
private Element getSelectedElement() {
Element selectedElement = Elements.getDocument().getActiveElement();
return selectedElement.getParentElement().isEqualNode(listElement) ? selectedElement : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ public void execute() {
if (needsFocus()) {
// save previous focus and set focus in popup
previousFocus = Elements.getDocument().getActiveElement();
listElement.getFirstElementChild().focus();
Element elementToFocus = listElement.getFirstElementChild();
elementToFocus.setAttribute("selected", "true");
elementToFocus.focus();
}

// add key event listener on popup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void onSuccess(ProposalApplyResult result) {

if (file instanceof Resource) {
final ChangeInfo changeInfo = result.getChangeInfo();
if (changeInfo != null) {
if (changeInfo != null && changeInfo.getName() != null) {
refactoringUpdater.updateAfterRefactoring(singletonList(changeInfo));
}
}
Expand Down