Skip to content
Permalink
Browse files

Merge pull request #5207 from rstudio/feature/show-vcs-commit-chars

Show number of characters when typing a commit message
  • Loading branch information...
jmcphers committed Aug 12, 2019
2 parents ba1bf90 + cef7a94 commit 1e398059754f4644eac1dc7dca303b511352ce5c
@@ -12,6 +12,7 @@
* PowerShell Core option in terminal (Windows-only)
* Custom terminal shell option for Windows desktop (previously only on Mac, Linux, and server)
* Keyboard shortcuts for main menu items on RStudio Server (e.g. Ctrl+Alt+F for File menu)
* Show number of characters when entering version control commit messages (#5192)

### Bugfixes

@@ -14,6 +14,8 @@
*/
package org.rstudio.studio.client.workbench.views.vcs.git.dialog;

import com.google.gwt.aria.client.LiveValue;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
@@ -35,12 +37,14 @@
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.*;
import com.google.gwt.user.client.ui.PopupPanel.PositionCallback;
import com.google.inject.Inject;

import org.rstudio.core.client.BrowseCap;
import org.rstudio.core.client.WidgetHandlerRegistration;
import org.rstudio.core.client.a11y.A11y;
import org.rstudio.core.client.command.AppCommand;
import org.rstudio.core.client.command.KeyboardShortcut;
import org.rstudio.core.client.dom.DomUtils;
@@ -298,6 +302,13 @@ public void onClick(ClickEvent event)

lblCommit_.setFor(commitMessage_);
lblContext_.setFor(contextLines_);

// Hide frequently-updating character count from screen readers
A11y.setARIAHidden(lblCharCount_);

// Expose a screen reader-only element with debounced updates
Roles.getStatusRole().set(lblReaderCharCount_.getElement());
Roles.getStatusRole().setAriaLiveProperty(lblReaderCharCount_.getElement(), LiveValue.POLITE);

unstagedCheckBox_.addValueChangeHandler(new ValueChangeHandler<Boolean>()
{
@@ -325,6 +336,18 @@ public void onValueChange(ValueChangeEvent<Boolean> e)
listBoxAdapter_ = new ListBoxAdapter(contextLines_);

FontSizer.applyNormalFontSize(commitMessage_);
commitMessage_.addKeyUpHandler(e ->
{
// Update commit message whenever keys are pressed
updateCharCount();
});
commitMessage_.addChangeHandler(e ->
{
// Update commit message whenever the text content changes; catches
// e.g. changes on blur after a mouse paste
updateCharCount();
});

new WidgetHandlerRegistration(this)
{
@Override
@@ -654,6 +677,24 @@ public void execute()
});
}

/**
* Update the character count for the commit message, or clear it if there
* are no longer any characters in the commit message.
*/
private void updateCharCount()
{
int length = commitMessage_.getText().length();
if (length == 0)
lblCharCount_.setText("");
else
lblCharCount_.setText(length + " characters");

// Debounce an update to the accessible character count
if (updateCharCountTimer_.isRunning())
updateCharCountTimer_.cancel();
updateCharCountTimer_.schedule(2000);
}

@UiField(provided = true)
SplitLayoutPanel splitPanel_;
@UiField(provided = true)
@@ -679,6 +720,10 @@ public void execute()
@UiField
FormLabel lblCommit_;
@UiField
Label lblCharCount_;
@UiField
Label lblReaderCharCount_;
@UiField
TextArea commitMessage_;
@UiField
CheckBox commitIsAmend_;
@@ -690,6 +735,8 @@ public void execute()
HorizontalPanel toolbarWrapper_;
@UiField
CheckBox ignoreWhitespaceCheckbox_;
@UiField
HTMLPanel panelCharCount_;

private ListBoxAdapter listBoxAdapter_;

@@ -704,6 +751,22 @@ public void execute()
private LeftRightToggleButton switchViewButton_;

private SizeWarningWidget overrideSizeWarning_;

/**
* Timer for updating the accessible character count
*/
private Timer updateCharCountTimer_ = new Timer()
{
@Override
public void run()
{
int length = commitMessage_.getText().length();
if (length == 0)
lblReaderCharCount_.setText("");
else
lblReaderCharCount_.setText(length + " characters in message");
}
};

private static final Resources RES = GWT.create(Resources.class);
static {
@@ -5,6 +5,7 @@
xmlns:rs_widget='urn:import:org.rstudio.core.client.widget'>

<ui:with field="res" type="org.rstudio.studio.client.workbench.views.vcs.git.dialog.GitReviewPanel.Resources"/>
<ui:with field="themeRes" type="org.rstudio.core.client.theme.res.ThemeResources"/>

<g:SplitLayoutPanel ui:field="splitPanel_" styleName="{res.styles.splitPanel}">
<g:north size="230">
@@ -19,7 +20,19 @@
<g:east size="400">
<g:LayoutPanel>
<g:layer left="6px" right="6px" top="4px" height="20px">
<rs_widget:FormLabel ui:field="lblCommit_" text="Commit message"/>
<g:HorizontalPanel width="100%">
<g:cell horizontalAlignment="ALIGN_LEFT">
<rs_widget:FormLabel ui:field="lblCommit_" text="Commit message"/>
</g:cell>
<g:cell horizontalAlignment="ALIGN_RIGHT">
<g:HTMLPanel>
<g:Label ui:field="lblCharCount_"/>
<g:HTMLPanel ui:field="panelCharCount_" styleName="{themeRes.themeStyles.visuallyHidden}">
<g:Label ui:field="lblReaderCharCount_"/>
</g:HTMLPanel>
</g:HTMLPanel>
</g:cell>
</g:HorizontalPanel>
</g:layer>
<g:layer left="6px" right="6px" top="20px" bottom="34px">
<g:TextArea ui:field="commitMessage_" styleName="{res.styles.commitMessage}"/>

0 comments on commit 1e39805

Please sign in to comment.
You can’t perform that action at this time.