After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756363 - Typing a command wrongly results in your message being removed
Typing a command wrongly results in your message being removed
Status: RESOLVED FIXED
Product: polari
Classification: Applications
Component: general
3.18.x
Other Linux
: Normal normal
: ---
Assigned To: Polari maintainers
Polari maintainers
Depends on:
Blocks:
 
 
Reported: 2015-10-10 22:17 UTC by Bastian Ilsø
Modified: 2015-10-18 11:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
picture showing a less destructive way to approach unknown commands. (27.05 KB, image/png)
2015-10-10 22:17 UTC, Bastian Ilsø
  Details
Select text and show styled error (6.14 KB, patch)
2015-10-15 21:23 UTC, Kunaal Jain
none Details | Review
Select text and show styled error (5.69 KB, patch)
2015-10-17 22:23 UTC, Kunaal Jain
committed Details | Review

Description Bastian Ilsø 2015-10-10 22:17:42 UTC
Created attachment 313034 [details]
picture showing a less destructive way to approach unknown commands.

I just typed a longer "/me" message and then the whole message was removed because i forgot a space between /me and the word coming after that. It would be more user-friendly if we select the whole chat message and possibly style the entry with ".error" . Then the user can either change the command if he typoed it or remove the message by just pressing delete or backspace. See attached screenshot proposal.
Comment 1 Florian Müllner 2015-10-10 23:01:14 UTC
(In reply to Bastian Ilsø from comment #0)
> picture showing a less destructive way to approach unknown commands.

I like it!
Comment 2 Kunaal Jain 2015-10-12 09:26:06 UTC
(In reply to Bastian Ilsø from comment #0)
> Created attachment 313034 [details]
> picture showing a less destructive way to approach unknown commands.
> 
> I just typed a longer "/me" message and then the whole message was removed
> because i forgot a space between /me and the word coming after that. It
> would be more user-friendly if we select the whole chat message and possibly

+1

I just wrote a patch for that :)

> style the entry with ".error" . Then the user can either change the command
> if he typoed it or remove the message by just pressing delete or backspace.
> See attached screenshot proposal.

There is particular problem on attaching style, When do we remove the style? There is no clear event when we should remove the error style. I must be missing something, please point it out.
Comment 3 Bastian Ilsø 2015-10-12 09:29:15 UTC
(In reply to Kunaal Jain from comment #2)
> +1
> 
> I just wrote a patch for that :)

Awesome!

> There is particular problem on attaching style, When do we remove the style?
> There is no clear event when we should remove the error style. I must be
> missing something, please point it out.

Remove the style again once a change is made to the text in the entry (so it turns blue when either the whole text was removed or the command was fixed).
Comment 4 Kunaal Jain 2015-10-15 21:23:46 UTC
Created attachment 313402 [details] [review]
Select text and show styled error
Comment 5 Florian Müllner 2015-10-15 23:31:54 UTC
Review of attachment 313402 [details] [review]:

::: src/entryArea.js
@@ +91,3 @@
             function() {
+                let isError = this._ircParser.process(this._entry.text);
+                if (isError == 0)

Eeeks. "isError" sounds like a bool, but you made process() return a number instead - this isn't C, let's use true/false. That will also make the code obvious enough to drop the additional variable:

if (this._ircParser.process(text) {
  ...
} else {
  ...
}

@@ +93,3 @@
+                if (isError == 0)
+                    this._entry.text = '';
+                else {

Style nit:
No braces when all blocks are one liners, braces for all blocks otherwise.

@@ +94,3 @@
+                    this._entry.text = '';
+                else {
+                    this._entry.get_style_context().add_class('polari-error-command');

The default theme already has a suitable class - 'error' - which should be used instead.

@@ +95,3 @@
+                else {
+                    this._entry.get_style_context().add_class('polari-error-command');
+                    this._entry.grab_focus();

The entry always has keyboard focus when activated, so please add a small comment:

this._entry.grab_focus(); // select text

::: src/ircParser.js
@@ +91,3 @@
                 if (command && knownCommands[command])
                     output = this._createFeedbackUsage(command);
+                else if (command) {

See previous comment about braces style.

Alternatively use something like:

retval = (command == null || knownCommands[command] != null);

and leave the rest as-is (or possibly reorder as:

if (!retval) // error
   output = ...
else if (command)
  output = ...
else
  output = ...

@@ +264,3 @@
                 break;
             }
+            default: {

Adding braces here is fine, just a quick explanation for the current code:
The command use braces to avoid scoping issues with local variables: Without braces, the first command to use a particular name needs to declare the variable with let, while all following command must not re-declare the same variable (i.e. no let). This makes adding additional commands cumbersome, so each uses its own local variable scope instead.
I can't think of any reason why the default case would ever need a local variable, so that's why I avoided the braces there (but again, I don't mind the addition either).
Comment 6 Kunaal Jain 2015-10-17 22:23:35 UTC
Created attachment 313593 [details] [review]
Select text and show styled error
Comment 7 Kunaal Jain 2015-10-17 22:27:43 UTC
(In reply to Florian Müllner from comment #5)
> Adding braces here is fine, just a quick explanation for the current code:
> The command use braces to avoid scoping issues with local variables: Without
> braces, the first command to use a particular name needs to declare the
> variable with let, while all following command must not re-declare the same
> variable (i.e. no let). This makes adding additional commands cumbersome, so
> each uses its own local variable scope instead.
> I can't think of any reason why the default case would ever need a local
> variable, so that's why I avoided the braces there (but again, I don't mind
> the addition either).

Didn't know that. Removed braces for now. In future if needed, we will add it.

Quick question, can I make a personal branch in wip or somewhere else to commit my changes?
Comment 8 Florian Müllner 2015-10-17 23:34:10 UTC
(In reply to Kunaal Jain from comment #7)
> Didn't know that. Removed braces for now.

Nah, as I said, it's fine ...


> Quick question, can I make a personal branch in wip or somewhere else to
> commit my changes?

If you have commit access, sure (we've started to use a convention of personal prefixes, e.g. wip/fmuellner/some-stuff).
Comment 9 Kunaal Jain 2015-10-18 05:29:48 UTC
(In reply to Florian Müllner from comment #8)
> (In reply to Kunaal Jain from comment #7)
> > Didn't know that. Removed braces for now.
> 
> Nah, as I said, it's fine ...
> 
> 
> > Quick question, can I make a personal branch in wip or somewhere else to
> > commit my changes?
> 
> If you have commit access, sure (we've started to use a convention of
> personal prefixes, e.g. wip/fmuellner/some-stuff).

I do have. In case you missed, I have uploaded patch.
Comment 10 Florian Müllner 2015-10-18 08:43:46 UTC
(In reply to Kunaal Jain from comment #9)
> I do have. In case you missed, I have uploaded patch.

Yes, I did miss that. Still, for review please attach patches to the appropriate bugs.
Comment 11 Kunaal Jain 2015-10-18 09:17:09 UTC
(In reply to Florian Müllner from comment #10)
> Yes, I did miss that. Still, for review please attach patches to the
> appropriate bugs.

Yes I have aready attached the patch for review. Attachment 313593 [details]
Comment 12 Florian Müllner 2015-10-18 09:21:56 UTC
Review of attachment 313593 [details] [review]:

LGTM

::: src/entryArea.js
@@ +187,2 @@
     _onEntryChanged: function() {
+        this._entry.get_style_context().remove_class('error'); // remove error class if present

Superfluous comment
Comment 13 Kunaal Jain 2015-10-18 09:42:03 UTC
Review of attachment 313593 [details] [review]:

Pushed to master with hash 4f53516fdfc15. Please mark the bug resolved.