Closed Bug 576642 Opened 14 years ago Closed 14 years ago

JSTerm: expanding/shrinking inputNode

Categories

(DevTools :: General, defect)

x86
All
defect
Not set
normal

Tracking

(blocking2.0 betaN+)

RESOLVED FIXED
Tracking Status
blocking2.0 --- betaN+

People

(Reporter: ddahl, Assigned: julian.viereck)

References

Details

(Whiteboard: [kd4b4])

Attachments

(2 files, 2 obsolete files)

In Jesse's JSShell, if you hit shift-enter the input node on the shell expands in height by one line, and a newline is added to the input value. 

It will also be handy to have a button that expands and shrinks the code input node.
Assignee: nobody → jviereck
Blocks: 529086
Adding multi line support to the textbox is as easy as adding a "multiline": "true" to the input node.

The bigger problem is to adjust the size when new lines are added. There is an `overflow` event that is fired on the textbox when a new line is added and lines doesn't fit in the current viewport of the textbox. I found an example on the internet that increases the number of rows by one when the `overflow` event occurs. Whereas this works for the hitting SHIFT+ENTER case, it doesn't work when pasting some text that causes more then 1 line to be added. The overflow event is fired just once although more rows need to be added. There is also the problem of shrinking the textbox again.

To implement this feature, a function/property is required, that returns the height of all the textbox's lines. Then after hitting a key combo or after the paste event took place, the height of the inputNode could get recalculated and the layout aligned. I tried things like 

    inputNode.scrollHeight
    inputNode.boxObject.height
    inputNode.inputField.scrollHeight

but all this retuned false values.

I'll try to think of other solutions, but ideas are welcome ;)
did you look at the code in Jesse Ruderman's JSShell? Perhaps it is only expanding by one line when you hit shift-enter.

What about on keypress you check the number of newlines and adjust the height to 1 line height higher? when there are no newlines you keep it to 1 line high.

At some point in the future we may have to think about XBL for this entire interface.
(In reply to comment #2)
> What about on keypress you check the number of newlines and adjust the height
> to 1 line height higher? when there are no newlines you keep it to 1 line high.

The problem is, that I don't know the height of one line. Otherwise it would be easy.
Jesse's jsshell is using a textarea in HTML. Implementation's going to be a little different.
I was thinking that if you had to, you could use 2 input nodes, swapping between them as needed. One that is set as not multiline and one that is multiline
That sounds tricksy. You should be able to do this with only one textbox. I'm wondering if there's some magical event you can fire to get the elements to resize/reflow themselves appropriately?
(In reply to comment #6)
> That sounds tricksy. You should be able to do this with only one textbox. 

I think we decided it would be best to just set both attributes (multiline and rows) when we detect the first line break 

what do you think enn?
(In reply to comment #7)
> (In reply to comment #6)
> > That sounds tricksy. You should be able to do this with only one textbox. 
> 
> I think we decided it would be best to just set both attributes (multiline and
> rows) when we detect the first line break 
> 
> what do you think enn?

I tried this. The problem is, that the first shift+enter can be detected using a keydown event listener. When you set multiline to true, the pressed key shift+enter doesn't cause a new line break (I guess because the textbox was not multiline when the shift+enter key was pressed) which means you have to emulate this inside of the keypress method. That looks like a hack to me.

Something I want to try is setting multiline="true", rows="1"for the xul:textbox and on the html:textarea used by the xul:textbox style="overflow-x:hidden", which should give a textbox that looks like a textbox with multiline="false". When the shift+enter key is pressed, the number of rows is increased.
according to Enn on irc:

 ddahl: using two elements, one multiline and one single is your best bet I think
(In reply to comment #9)
> according to Enn on irc:
> 
>  ddahl: using two elements, one multiline and one single is your best bet I
> think

well, I sit corrected!
Attached patch Patch (obsolete) — Splinter Review
Note: I changed the line-height from 1.6em to 1.2em because that looks better to me when having multiple lines. I'm not sure how this behaves on Linux/Windows.
Attachment #459412 - Flags: feedback?(ddahl)
(In reply to comment #11)
> Created attachment 459412 [details] [diff] [review]
> Patch
> 
> Note: I changed the line-height from 1.6em to 1.2em because that looks better
> to me when having multiple lines. I'm not sure how this behaves on
> Linux/Windows.

That looks good on linux too, no worries
Comment on attachment 459412 [details] [diff] [review]
Patch

Looks good, Julian
Attachment #459412 - Flags: feedback?(ddahl) → feedback+
Comment on attachment 459412 [details] [diff] [review]
Patch

Requesting approval for this bug because it improves the way the user can work with the WebConsole. Instead of entering only one line strings, he can enter multiple lines as well and edit them. Also, multiline text pasted into the WebConsole's inputNode stays multiline which is more user friendly.
Attachment #459412 - Flags: review?
Attachment #459412 - Flags: approval2.0?
blocking2.0: --- → betaN+
Attachment #459412 - Flags: review? → review?(robert.bugzilla)
Comment on attachment 459412 [details] [diff] [review]
Patch

First reaction whenever I see a setTimeout is always r-. I'd prefer it if you got enn to review it since he usually comes up with elegant solutions that don't require a setTimeout.
Attachment #459412 - Flags: review?(robert.bugzilla) → review?(enndeakin)
Attachment #459412 - Flags: review?(enndeakin)
Attachment #459412 - Flags: approval2.0?
Whiteboard: [kd4b4]
Attached patch Patch rebased (obsolete) — Splinter Review
Attachment #459412 - Attachment is obsolete: true
Attachment #462082 - Flags: review?
Who are you looking for review from? it is not marked with a reviewer.:)
Attachment #462082 - Flags: review? → review?(enndeakin)
Comment on attachment 462082 [details] [diff] [review]
Patch rebased

>+      // When the keyDown event was performed, set the number of rows to the
>+      // number of new lines.
>+      setTimeout(function() {
>+        self.inputNode.setAttribute("rows",
>+          Math.min(8, self.inputNode.value.split("\n").length));
>+      }, 0);
>+

This code will only get called when a key is pressed. It will not be called when the user pastes into it or drags text and drops it there (both of which can change the value). You likely really want to use the 'input' event, which fires when the user changes the value by any means (and only then, as keydown can also fire when the value hasn't changed as well.)


>+            if (aEvent.cancelable) {
>+              aEvent.preventDefault();
>+            }

Just aEvent.preventDefault() is sufficient.

I'm not particularly fond of auto-resizable textfields though. I would just add resizable="true" so that the user can resize it themselves, although maybe the frame size will prevent that from working.
Attachment #462082 - Flags: review?(enndeakin) → review-
(In reply to comment #18)
> Comment on attachment 462082 [details] [diff] [review]
> Patch rebased
> 
> >+      // When the keyDown event was performed, set the number of rows to the
> >+      // number of new lines.
> >+      setTimeout(function() {
> >+        self.inputNode.setAttribute("rows",
> >+          Math.min(8, self.inputNode.value.split("\n").length));
> >+      }, 0);
> >+
> 
> This code will only get called when a key is pressed. It will not be called
> when the user pastes into it or drags text and drops it there (both of which
> can change the value). You likely really want to use the 'input' event, which
> fires when the user changes the value by any means (and only then, as keydown
> can also fire when the value hasn't changed as well.)
> 
> 
> >+            if (aEvent.cancelable) {
> >+              aEvent.preventDefault();
> >+            }
> 
> Just aEvent.preventDefault() is sufficient.

Thanks for these hints Neil.

> 
> I'm not particularly fond of auto-resizable textfields though. I would just add
> resizable="true" so that the user can resize it themselves, although maybe the
> frame size will prevent that from working.

This works, but it's a strange behavior when the user adds a line break and then has to realize he has to drag the resizer at the right-bottom edge to see what he is typing. That's why I like the auto-resizeable way it is implemented in this patch.

@ddahl et. all: What do you think about this?
In this particular case, I think auto-resizing would actually be quite nice. From my experience using Firebug's console, many times I'm just running single line statements to evaluate. When I *do* want to write out a function, I find the switch from the single line interface to the multi-line one a bit jarring. Having to manually resize the element would be even more jarring (because I would have to reach for the mouse... if there's a way to expand the element via the keyboard, I don't know what it is)

Expanding to accommodate multiline input sounds great to me.
(In reply to comment #20)

> Expanding to accommodate multiline input sounds great to me.
Agreed, at the very least, lets get some feedback on this from beta users. I think this is a useful feature.
Attachment #462082 - Attachment is obsolete: true
Attachment #463176 - Flags: review?(enndeakin)
Attachment #463176 - Flags: review?(enndeakin) → review+
Keywords: checkin-needed
Keywords: checkin-needed
We should get approval for this. cool!
Attachment #463176 - Flags: approval2.0?
(In reply to comment #23)
> We should get approval for this. cool!

Getting feedback for this cool feature in the next beta would be very useful.
Attachment #463176 - Flags: approval2.0? → approval2.0+
Keywords: checkin-needed
Comment on attachment 463176 [details] [diff] [review]
[backed-out] Patch 2 improved on Neil's feedback + unit tests

http://hg.mozilla.org/mozilla-central/rev/cfc0accaf8b2
Attachment #463176 - Attachment description: Patch 2 improved on Neil's feedback + unit tests → [checked-in] Patch 2 improved on Neil's feedback + unit tests
Status: NEW → RESOLVED
Closed: 14 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Doesn't work due to conflict with the prompt (bug 583349). Will likely back out.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
we need to back this out due to the conflict mentioned in comment #27. It's 10:30pm here and we're waiting for a clean run on a windows clobber build. ETA is no less than 3 hours so I'm waiting to do this tomorrow unless somebody in a different timezone can manage it.
Whiteboard: [kd4b4] → [kd4b4][needs-backout]
Whiteboard: [kd4b4][needs-backout] → [kd4b4]
Attachment #463176 - Attachment description: [checked-in] Patch 2 improved on Neil's feedback + unit tests → [backed-out] Patch 2 improved on Neil's feedback + unit tests
http://hg.mozilla.org/mozilla-central/rev/a4b18999dc5b
Status: REOPENED → RESOLVED
Closed: 14 years ago14 years ago
Resolution: --- → FIXED
Comment on attachment 464576 [details] [diff] [review]
[checked-in] Proposed patch, version 2 (rebased to trunk 2010-08-10).

http://hg.mozilla.org/mozilla-central/rev/a4b18999dc5b
Attachment #464576 - Attachment description: Proposed patch, version 2 (rebased to trunk 2010-08-10). → [checked-in] Proposed patch, version 2 (rebased to trunk 2010-08-10).
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: