Skip to content

Commit

Permalink
improved keyboard handling for the help pane
Browse files Browse the repository at this point in the history
  • Loading branch information
jjallaire committed Sep 4, 2012
1 parent 1c609f7 commit 41dbd9c
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 52 deletions.
16 changes: 10 additions & 6 deletions src/cpp/session/modules/SessionHelp.cpp
Expand Up @@ -200,12 +200,16 @@ bool handleRShowDocFile(const core::FilePath& filePath)
}
}

// javascript callbacks to inject into page so that next/prev buttons work
const char * const kJsNavigateCallbacks =
// javascript callbacks to inject into page
const char * const kJsCallbacks =
"<script type=\"text/javascript\">\n"
"if (window.parent.helpNavigated)\n"
" window.parent.helpNavigated(document, window);"
"</script>";
" window.parent.helpNavigated(document, window);\n"
"if (window.parent.helpKeydown)\n"
" window.onkeydown = function(e) {window.parent.helpKeydown(e);}\n"
"</script>\n";



class HelpContentsFilter : public boost::iostreams::aggregate_filter<char>
{
Expand Down Expand Up @@ -239,7 +243,7 @@ class HelpContentsFilter : public boost::iostreams::aggregate_filter<char>
"src=\"" + baseUrl + "/");

// append javascript callbacks
std::string js(kJsNavigateCallbacks);
std::string js(kJsCallbacks);
std::copy(js.begin(), js.end(), std::back_inserter(dest));
}
private:
Expand All @@ -252,7 +256,7 @@ class CustomHelprContentsFilter
{
void do_filter(const std::vector<char>& src, std::vector<char>& dest)
{
std::string js(kJsNavigateCallbacks);
std::string js(kJsCallbacks);
std::copy(src.begin(), src.end(), std::back_inserter(dest));
std::copy(js.begin(), js.end(), std::back_inserter(dest));
}
Expand Down
7 changes: 7 additions & 0 deletions src/gwt/src/org/rstudio/core/client/dom/WindowEx.java
Expand Up @@ -52,6 +52,13 @@ public final native void forward() /*-{
this.history.forward() ;
}-*/;

public final native void removeSelection() /*-{
selection = this.getSelection();
if (selection != null) {
selection.removeAllRanges();
}
}-*/;

public final native boolean find(String term,
boolean matchCase,
boolean searchUpward,
Expand Down
Expand Up @@ -21,7 +21,7 @@ public class NativeKeyDownEvent extends GwtEvent<NativeKeyDownHandler>
public static final GwtEvent.Type<NativeKeyDownHandler> TYPE =
new GwtEvent.Type<NativeKeyDownHandler>();

protected NativeKeyDownEvent(NativeEvent event)
public NativeKeyDownEvent(NativeEvent event)
{
event_ = event;
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.google.inject.name.Named;
import org.rstudio.core.client.Debug;
import org.rstudio.core.client.Triad;
import org.rstudio.core.client.dom.WindowEx;
import org.rstudio.core.client.events.WindowStateChangeEvent;
import org.rstudio.core.client.layout.DualWindowLayoutPanel;
import org.rstudio.core.client.layout.LogicalWindow;
Expand Down Expand Up @@ -254,6 +255,7 @@ public WorkbenchTab[] getAllTabs()

public void activateTab(Tab tab)
{
WindowEx.get().focus();
tabToPanel_.get(tab).selectTab(tabToIndex_.get(tab));
}

Expand Down
Expand Up @@ -160,8 +160,21 @@ public void onEnsureVisible(EnsureVisibleEvent event)
public void selectTab(int tabIndex)
{
if (tabPanel_.getSelectedIndex() == tabIndex)
{
// if it's already selected then we still want to fire the
// onBeforeSelected and onSelected methods (so that actions
// like auto-focus are always taken)
int selected = getSelectedIndex();
if (selected != -1)
{
WorkbenchTab tab = tabs_.get(selected);
tab.onBeforeSelected();
tab.onSelected();
}

return;

}

// deal with migrating from n+1 to n tabs, and with -1 values
int safeIndex = Math.min(Math.max(0, tabIndex), tabs_.size() - 1);

Expand Down
Expand Up @@ -17,6 +17,7 @@
import com.google.inject.Inject;
import org.rstudio.core.client.command.CommandBinder;
import org.rstudio.core.client.command.Handler;
import org.rstudio.core.client.dom.WindowEx;
import org.rstudio.core.client.layout.DelayFadeInHelper;
import org.rstudio.studio.client.application.events.EventBus;
import org.rstudio.studio.client.workbench.commands.Commands;
Expand Down Expand Up @@ -80,6 +81,7 @@ public void onConsolePrompt(ConsolePromptEvent event)
@Handler
void onActivateConsole()
{
WindowEx.get().focus();
view_.bringToFront();
view_.focus();
}
Expand Down
Expand Up @@ -50,6 +50,7 @@ public interface Display extends WorkbenchView,
void print() ;
void popout() ;
void refresh() ;
void focus();

LinkMenu getHistory() ;

Expand Down

1 comment on commit 41dbd9c

@ches
Copy link

@ches ches commented on 41dbd9c Sep 12, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.