Closed Bug 98160 Opened 23 years ago Closed 13 years ago

Replace Accel+Shift+X (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows

Categories

(Core :: DOM: Editor, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla9

People

(Reporter: xslf, Assigned: ehsan.akhgari)

References

(Depends on 1 open bug)

Details

(6 keywords, Whiteboard: see comment 17)

Attachments

(2 files, 4 obsolete files)

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.3+) Gecko/20010831
BuildID:    2001083103

in windows systems, left ctrl+shift changes alignment/directionality to LTR and
right ctrl+shift changes alignment/directionality to RTL. This is a standard
feature, that works in almost all windows applications.
However, it does not work in textarea under Mozilla

Reproducible: Always
Steps to Reproduce:
1. Load any form with textarea into Mozilla (you can use the attached one)
2. Use Left ctrl + shift or right ctrl + shift to change the
alignment/directionality


Actual Results:  Nothing happends

Expected Results:  The alignment/directionality should change

Lots of Isralie web sites depend on this feature in there web forms. It is very
common to see directions telling the user to use this method if they wish to
write in the other langues (Hebrew or English).
With this feature missing, it is a real pain to right English in RTL forms, and
Hebrew in LTR forms.

BTW, this is not limited to textareas- almost no dialog boxes in Mozilla respond
to this, which makes creating Hebrew folder names for bookamrs, editing Hebrew
bookmark names etc. a real pain.
Attached file Simple form with RTLtextarea. (deleted) —
Status: UNCONFIRMED → NEW
Ever confirmed: true
I discovered the same problem with Mozilla mail- you can't set plain text mail
to right-to-left, which makes it a real pain to read/write Hebrew email.
Should I open a separete bug for it?
Yes, please do open a separate RFE bug for directionality in mail. It was
discussed as a side issue in bug 95371, and is on my personal TODO list, but it
deserves its own bug.
Blocks: 115711
Assigning to myself to get on intl nsbeta1 radar. mkaply, feel free to do the
same with any other bugs that are currently assigned to you, if appropriate.
Assignee: mkaply → smontagu
Keywords: nsbeta1
nsbeta1- too late for unknown issue. 
Keywords: nsbeta1nsbeta1-
Status: NEW → ASSIGNED
batch: adding topembed per Gecko2 document
http://rocknroll.mcom.com/users/marek/publish/Gecko/Gecko2Tasks.html
Keywords: topembed
Keywords: topembedembed, topembed-
Blocks: grouper
The bugreport was initially submitted for a windows system....
But i would rather like this feature be introduced in mozilla-linux, too.
The textareas as well as regular <input type="text" ..> are hardly usable on all
systems when dir="rtl" secified for them in the document.
Please change the title of this bug to "Can't change alignment/directionality in
a textarea" and mark this as a problem for all operating systems and all platforms.

The Ctrl+Shift shortcut is only valid for Windows, but the problem affects
everyone - including users of operating systems without native Hebrew support
(such as BeOS and most unices).

When Bug 85420 ("Need Bidi UI") is solved we'll have a reasonable solution, but
a keyboard shortcut will definitely be a welcomed addition to Mozilla users on
platforms other than Windows.

Prog.
Depends on: bidiui
OS: Windows 98 → All
Hardware: PC → All
Summary: Can't change alignment/directionality in a textarea using ctrl shift → Can't change alignment/directionality in a textarea a textarea
Summary: Can't change alignment/directionality in a textarea a textarea → Can't change alignment/directionality in a textarea
Jesse Ruderman from squarefree.com made for us a quick direction switcher for
textareas, which has a bookmarklet installation. 

javascript:(function(){var
D=document,B=D.body,sx=B.scrollLeft,sy=B.scrollTop,k,i,f,j,x,r,p,a;for(i=0;f=D.forms[i];++i)for(j=0;x=f[j];++j)x.onblur=function(){for(p=k=this;p&&!p.dir;p=p.parentNode);r=p?(p.dir=="rtl"):0;k.dir=(r?"ltr":"rtl");};a=D.createElement("a");a.href="#";B.appendChild(a);a.focus();setTimeout(function(){for(i=0;f=D.forms[i];++i)for(j=0;x=f[j];++j)x.onblur=null;if(k)k.focus();else
alert("No focused
textbox!");B.removeChild(a);B.scrollLeft=sx;B.scrollTop=sy;},0)})() 


Still, we have another two workarounds, which have been discussed here and at
mozilla.org.il (hebrew):
A. Ilya Konstantinov's -
http://toast.unwind.co.il/hacks/mozBidiBindings-0.3.tar.gz - No automatic
installation, XBL based.
B. Mooffie's  - http://archive.takilla.com/SiteBuilders/msg01342.html (Hebrew,
but still readable) - One line addition to platformHTMLBindings.xml, shorter, no
automatic installation.

Now if we will get the ability to bind ctrl-shift to one of those...
From Comment #9:

>Jesse Ruderman from squarefree.com made for us a quick direction switcher for
>textareas, which has a bookmarklet installation. 

This doesn't seem to work with Camino :-(
Btw, you have to put that bookmarklet on your bookmarks toolbar to use it; you
can't use it directly from the address bar.  That's because it depends on a
textbox or textarea being focused.

If Camino makes the bookmarks toolbar take focus when you click a bookmarklet,
you can use a bookmarklet that does one of the following instead:
- changes direction of all textareas.
- adds the ctrl+shift shortcut for the current page.
- changes the cursor and waits for you to click the textarea you want to change.
Hmm.. restarted the browser and now it seems to work. Perhaps it was a fluke.

>adds the ctrl+shift shortcut for the current page

As far as I know, that shortcut is windows only. Camino runs on mac OS. Am I
mistaken here?
*** Bug 223001 has been marked as a duplicate of this bug. ***
Blocks: 240501
*** Bug 240243 has been marked as a duplicate of this bug. ***
Blocks: 241587
*** Bug 247021 has been marked as a duplicate of this bug. ***
"Switch Text Direction" menu item (see bug 85420) has been checked in for
Firefox, and will be checked in soon for Seamonkey. The current keyboard
shortcut is Accel+Shift+Y. We know it is bad, but because of bug 166240 we can't
implement ctrl+right/left shift at the moment.

As crtl+shift is windows-only standard, I suggest ctrl (not accel)+right/left
arrows on other platforms.

(as far as I know, only on windows ctrl+arrows select a word in textareas,
correct me if i'm wrong).
Severity: normal → enhancement
Depends on: 166240
QA Contact: zach → bugs.mano
Summary: Can't change alignment/directionality in a textarea → Replace Accel+Shift+Y (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows, Ctrl (not accel)+arrows on other platforms
Whiteboard: see comment 17
Component: Layout: BiDi Hebrew & Arabic → Keyboard: Navigation
Keywords: nsbeta1-, topembed-access, intl
Ctrl+Left/Right arrow jumps to the previous/next word in a textarea on
Linux/GTK2 as well. Add Shift to extend a selection.
Summary: Replace Accel+Shift+Y (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows, Ctrl (not accel)+arrows on other platforms → Replace Accel+Shift+X (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows / Linux ; Ctrl (not accel)+arrows on OS X
Depends on: dom3_events
*** Bug 321687 has been marked as a duplicate of this bug. ***
Possible solution here: http://eesh.net/MozCtrlShift.html
I have no idea if this is relevant for XUL, I hope it helps. This is, of course, just a proof of concept.

Demonstrated on a textarea, works on an input (type=text) too.
See progress of implementing this in an extention in: http://bugzilla.mozdev.org/show_bug.cgi?id=15075
Keywords: rtl
Chromium is gaining users and have recently got ctrl-shift change direction support in its nightlies. Please implement this in Gecko, so we will be able to get rid of the ctrl-shift-x hotkey and the 'switch direction' context menu item.
Taking.
Assignee: smontagu → mano
Depends on: 493971
QA Contact: mano → keyboard.navigation
Several times recently (using FF 3.6.6 on OSX 10.6.4) I've enabled RTL by mistake, probably because the current shortcut is so close to Cut (Cmd-X).

The lack of context menu makes the mistake difficult to rectify.  In the end, I resorted to google, and found this page:

http://support.mozilla.com/en-US/kb/Text+entered+into+Firefox+is+backwards

The proposed Ctrl-left/right sequence still seems prone to accidents (e.g. if using Alt-left/right to cursor across words).  It makes me wonder: should this feature really be enabled for all locales by default?  I don't know what percentage of Firefox users want this feature, but I expect they are small minority, and highly localised.

I think it would make sense to have a preference for "Fast RTL toggle", which would be disabled by default for most locales.
Do you have any news about this bug?
Do you plan to implement the Ctrl+Left/Right Shift for switching text direction ?

Please let me know
Thanks
Hello,

Please find in attachment a patch for fixing the problem on Windows/Linux
In this pacth the direction of the text is changed upon Ctrl+Shift key pressing
Please observe that no distinction is made between Right Ctrl+Shift and Left Ctrl+Shift.
It seems even impossible to implement (at least by looking at the following article: http://stackoverflow.com/questions/2847135/check-ctrl-shift-alt-keys-on-click-event).
Please let me know your commnents/suggestions
How do you install the patch. Clicking on the attachment simply shows a page of JS code
Sorry. I have not generated the patch from the top level directory.

Now I guess you can install the patch by running the following command from the top level directory:

patch -p0 < <the attached patch>
Attached patch Last Patch using DOM_VK_SHIFT and CONTROL (obsolete) (deleted) — Splinter Review
The current shortcut keys are implemented here: <http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser-sets.inc#346>.  But XUL <key> elements do not support events for ctrl+alt, which is sad...

Gavin, what do you think would be the acceptable solution here?
You can use my workaround suggested in comment 20...
Any comments about the patch I posted a week ago ?
Hey, this bug is more than ten years old (!!!). Let's fix it already.
wajnberg@il.ibm.com, I'm terribly sorry that I missed your earlier comments and patches on this bug.

While your general approach works, the correct fix is a bit more involved here.  Specifically, Ctrl+Left/Right Shift is a Windows only key combination, and it should only be handled if there are bidi keyboards installed on the system.  Also, this combination is not a mere toggle, if the left shift key is pressed, the direction should be switched to LTR, and if the right shift is pressed, it should be switched to RTL (thanks to Microsoft for coming up with this really complicated detail!).  I'm morphing this bug to be only about Windows.  For other platforms, we should file separate bugs if we find out about existing platform conventions.

I wrote a patch tonight to add this support, which I will attach shortly.  I wrote it on a Mac, so it's totally untested (it may not even compile!).  I'll submit it for review when I test it and make sure that it works as expected.
Assignee: mano → nobody
Component: Keyboard: Navigation → Editor
Summary: Replace Accel+Shift+X (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows / Linux ; Ctrl (not accel)+arrows on OS X → Replace Accel+Shift+X (Switches text direction) with more intuitive keyboard shortcuts: Ctrl+Left/Right Shift on Windows
Assignee: nobody → ehsan
QA Contact: keyboard.navigation → editor
Attached patch WIP (obsolete) (deleted) — Splinter Review
Attachment #529456 - Attachment is obsolete: true
Attachment #529655 - Attachment is obsolete: true
Attachment #529719 - Attachment is obsolete: true
For future reference, I came across this Chromium patch <http://src.chromium.org/viewvc/chrome?view=rev&revision=13588>, and I used some implementation ideas and code from the Chromium project, which I've specified in the patch itself.  Not sure if I need to add anything to about:license for this usage.
Attached patch Patch (v1) (deleted) — Splinter Review
OK, this version of the patch actually compiles, and works just fine!
Attachment #560294 - Attachment is obsolete: true
Attachment #560299 - Flags: review?(roc)
(In reply to Ehsan Akhgari [:ehsan] from comment #36)
>   Also, this combination is not a mere toggle, if
> the left shift key is pressed, the direction should be switched to LTR, and
> if the right shift is pressed, it should be switched to RTL (thanks to
> Microsoft for coming up with this really complicated detail!).

I find it difficult to use both key combinations, and sometimes find myself unable to change the direction because my right hand is actually used for the mouse movement. If I remember correctly, it was added only to more recent versions of Windows and before that it used to be a toggle key. If it doesn't take too much, I'd prefer if we can change this behavior using a preference or by an extension.
Comment on attachment 560299 [details] [diff] [review]
Patch (v1)

Review of attachment 560299 [details] [diff] [review]:
-----------------------------------------------------------------

::: editor/libeditor/base/nsEditorEventListener.cpp
@@ +395,5 @@
> +  } else {
> +    return false;
> +  }
> +
> +  // Scan the key status to find pressed keys. We should adandon changing the

abandon

@@ +459,5 @@
> +    if (keyCode == nsIDOMKeyEvent::DOM_VK_SHIFT) {
> +      bool switchToRTL;
> +      if (IsCtrlShiftPressed(switchToRTL)) {
> +        mShouldSwitchTextDirection = PR_TRUE;
> +        mSwitchToRTL = switchToRTL ? PR_TRUE : PR_FALSE;

just mSwitchToRTL = switchToRTL;
Attachment #560299 - Flags: review?(roc) → review+
Try run for 0c2293268a6d is complete.
Detailed breakdown of the results available here:
    http://tbpl.allizom.org/?tree=Try&usebuildbot=1&rev=0c2293268a6d
Results (out of 171 total builds):
    exception: 3
    success: 145
    warnings: 7
    failure: 16
Builds available at http://ftp.mozilla.org/pub/mozilla.org/firefox/try-builds/eakhgari@mozilla.com-0c2293268a6d
(In reply to Tomer Cohen :tomer from comment #40)
> (In reply to Ehsan Akhgari [:ehsan] from comment #36)
> >   Also, this combination is not a mere toggle, if
> > the left shift key is pressed, the direction should be switched to LTR, and
> > if the right shift is pressed, it should be switched to RTL (thanks to
> > Microsoft for coming up with this really complicated detail!).
> 
> I find it difficult to use both key combinations, and sometimes find myself
> unable to change the direction because my right hand is actually used for
> the mouse movement. If I remember correctly, it was added only to more
> recent versions of Windows and before that it used to be a toggle key. If it
> doesn't take too much, I'd prefer if we can change this behavior using a
> preference or by an extension.

For now, I would rather us be compatible with the platform conventions.  Note that the existing shortcut (Ctrl+Shift+X) is being preserved.
https://hg.mozilla.org/integration/mozilla-inbound/rev/66db4ae2f2c7
Flags: in-litmus?
Target Milestone: --- → mozilla9
For licensing: ideally, keep copied code in new files, but if not, make sure it's clearly marked. Add the name of the file or (if a whole directory) the name of the directory to the appropriate stanza in about:license.

Gerv
I added the appropriate information to about:license:

https://hg.mozilla.org/integration/mozilla-inbound/rev/67ad7402608f
For reference, note that Qt also uses Ctrl+Shift the way Windows does, that is, the left pair changes the field to LTR (and left aligned) and the right pair to RTL (right aligned). Qt only enables this when you enable support for RTL languages.

I don't know if GTK+ has a similar convention, but the Qt one, added to the fact that most Linux users (at least here in Israel) are well aware of Windows conventions, makes me think that Mozilla should adapt a similar behavior on Linux too.
https://hg.mozilla.org/mozilla-central/rev/66db4ae2f2c7
https://hg.mozilla.org/mozilla-central/rev/67ad7402608f
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
(In reply to shai from comment #47)
> For reference, note that Qt also uses Ctrl+Shift the way Windows does, that
> is, the left pair changes the field to LTR (and left aligned) and the right
> pair to RTL (right aligned). Qt only enables this when you enable support
> for RTL languages.
> 
> I don't know if GTK+ has a similar convention, but the Qt one, added to the
> fact that most Linux users (at least here in Israel) are well aware of
> Windows conventions, makes me think that Mozilla should adapt a similar
> behavior on Linux too.

Please file a bug to add this support to Qt.  I don't know a lot about the Qt APIs myself, so I would appreciate some help there.  :-)
From attachment 560299 [details] [diff] [review] [1] I understand that this fix is intended for Windows only. Will we have to keep using the other key binding under Linux and Mac? 

I understood previously that we intended to fix this bug when DOM3 events will get implemented in Gecko. Since this fix is not based on DOM3 (Am I right?), does it mean that we will prefer to remove this additional code in the future?



[1] https://bugzilla.mozilla.org/attachment.cgi?id=560299&action=diff#a/editor/libeditor/base/nsEditorEventListener.h_sec1
(In reply to Tomer Cohen :tomer from comment #50)
> From attachment 560299 [details] [diff] [review] I understand that this
> fix is intended for Windows only. Will we have to keep using the other key
> binding under Linux and Mac? 

Yes, this fix is Windows only.  I talked to Behdad about how GTK handles text direction change, and he told me that the way that GTK works natively is that when changing the keyboard layout, if the text field doesn't contain any characters with a strong direction, its direction is automatically switched to the direction of the keyboard layout, which is a behavior that I think is a lot more intuitive than what we have in Windows.  He also told me that we need to use _gdk_x11_keymap_state_changed in order to get notified when the keyboard layout changes.  So we can file a bug to do this on GTK.

For Mac, I'm not personally aware of any native keybindings for text control direction change.  Do you know of any?

> I understood previously that we intended to fix this bug when DOM3 events
> will get implemented in Gecko. Since this fix is not based on DOM3 (Am I
> right?), does it mean that we will prefer to remove this additional code in
> the future?

Well, the solution that I implemented works today!  :-)  When we get enough support in DOM3 so that we can avoid using Win32 API, we can remove that code.  But still I think that we want to emulate platform native behavior here, instead of adding Ctrl+Shift on all platforms.  Do you know of any other Linux/Mac app which handles the Ctrl+Shift keyboard toggle to direction of text controls?
Umm, sorry to chime in this late, I was only following dependent bugs. But I would still hope Ehsan or others could answer a couple of questions. 

- Is it now the case that Right-Shift can be told apart from Left-Shift?
- If not, how does the patch code differ (if it at all differs) from the Ctrl+Shift direction switching logic in BiDi Mail UI? i.e. the finite-state machine described here: 
http://www.mozdev.org/source/browse/bidiui/source/tbird/chrome/content/bidimailpack/bidimailpack-composer.js?rev=1.183
(line 12)
(In reply to Eyal Rozenberg from comment #52)
> Umm, sorry to chime in this late, I was only following dependent bugs. But I
> would still hope Ehsan or others could answer a couple of questions. 
> 
> - Is it now the case that Right-Shift can be told apart from Left-Shift?

Not using the DOM APIs yet.  I just used the Win32 API for doing that.

> - If not, how does the patch code differ (if it at all differs) from the
> Ctrl+Shift direction switching logic in BiDi Mail UI? i.e. the finite-state
> machine described here: 
> http://www.mozdev.org/source/browse/bidiui/source/tbird/chrome/content/
> bidimailpack/bidimailpack-composer.js?rev=1.183
> (line 12)

It differs to that logic in two ways:

1. It doesn't implement Ctrl+Shift as a direction toggle switch, it implements the Windows behavior of differentiating between right and left shift keys.
2. It only implements this behavior on systems with at least two keyboard layouts of different directions, to be compatible with Windows.
(In reply to Ehsan Akhgari [:ehsan] from comment #49)
> (In reply to shai from comment #47)
> > For reference, note that Qt also uses Ctrl+Shift the way Windows does, that
> > is, the left pair changes the field to LTR (and left aligned) and the right
> > pair to RTL (right aligned). Qt only enables this when you enable support
> > for RTL languages.
> > 
> > I don't know if GTK+ has a similar convention, but the Qt one, added to the
> > fact that most Linux users (at least here in Israel) are well aware of
> > Windows conventions, makes me think that Mozilla should adapt a similar
> > behavior on Linux too.
> 
> Please file a bug to add this support to Qt.  I don't know a lot about the
> Qt APIs myself, so I would appreciate some help there.  :-)

I seem to have been misunderstood: The intention was not "I need something like this in Qt", it was "Qt already has this, please copy their feature into mozilla".

I see by comment #51 that there is no intention to do this (on Linux); I think that's a pity, but, oh well.

Thank you for fixing the problem on Windows.
For the record, OpenOffice also implemented this keyboard shortcut on all three major platforms.
I filed bug 689246 for the Qt implementation.
Documentation updated:

https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIBidiKeyboard

Also mentioned on Firefox 9 for developers.
Hi, I can not use "right ctrl+shift" in last Firefox Nightly (11.0a1 (2011-11-17)). Is it disabled because I could use this feature around one week ago but now I can not and I must use ctrl+shift+x in Firefox (still I can use this shortkey on chrome or other windows programs)
Thank you.
Sorry, now working again, thanks :)
Flags: in-litmus?
Depends on: 962022
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: