Clicking a hyperlink erroneously adds an empty string to the command history

Posted by Kahenraz on Tue 03 Apr 2018 03:28 PM — 7 posts, 28,518 views.

#0
<alias
   name="TEST"
   match="test"
   enabled="y"
   omit_from_command_history="y"
   send_to="12"
   sequence="100"
  >
  <send>
    Hyperlink("test2", "info", "", "", "", 0)
    Note("")
  </send>
</alias>


This alias is just an example which places a hyperlink. The bug is that when clicking on a hyperlink, a blank entry is added to the command history.

For example:

> look
(player looks)
> test
(displays hyperlink)
> click hyperlink
(does link thing)

Now if you hit the up arrow it will show a blank entry instead of the last command in the history.

I'm trying to pair clicking on a link which sends one command to the world but the command sent to the history buffer is different: https://www.gammon.com.au/forum/?id=14229

The fact that there is a lank entry immediately after clicking on a link means that I always have to hit the up arrow twice instead of just once after clicking on a hyperlink.
Amended on Tue 03 Apr 2018 03:34 PM by Kahenraz
USA Global Moderator #1
I can confirm that clicking the given hyperlink adds an empty entry in the command history, though cycling past it and back seems to make it disappear (???).

A workaround would be to use the plugin function call format as discussed in https://mushclient.com/forum/bbshowpost.php?bbsubject_id=14211

Or possibly you could just immediately edit the command history via an alias to remove that extra empty entry.
Amended on Wed 04 Apr 2018 03:26 AM by Fiendish
Australia Forum Administrator #2
I can't reproduce that. No additional entry is being added to the command history. It might be related to what test2 does, which you haven't shown.

When you copy and paste aliases into forum messages can you please leave in the lines <aliases> ... </aliases> ?

I don't know how you are getting rid of them, or why, but it makes copying and pasting for testing harder.

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


Template:version
Please help us by advising the version of MUSHclient you are using. Use the Help menu -> About MUSHclient.
Australia Forum Administrator #3

The code for adding to the command history specifically disallows adding empty strings:

void CSendView::AddToCommandHistory (const CString & strCommand)
  {
CMUSHclientDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

// do not record null commands, or ones identical to the previous one
// also do not record if the server has suppressed echoes

  if (!strCommand.IsEmpty () &&     // <------------------------- HERE
      strCommand != m_last_command &&
      !(pDoc->m_bNoEcho && !pDoc->m_bAlwaysRecordCommandHistory)) 
    {
    if (m_inputcount >= pDoc->m_nHistoryLines)
      {
      m_msgList.RemoveHead ();   // keep max of "m_nHistoryLines" previous commands
      m_HistoryFindInfo.m_nCurrentLine--;     // adjust for a "find again"
      if (m_HistoryFindInfo.m_nCurrentLine < 0)
        m_HistoryFindInfo.m_nCurrentLine = 0;
      }
    else
      m_inputcount++;
    m_msgList.AddTail (strCommand);  // <----- COMMAND ADDED HERE
    m_last_command = strCommand;
    }

  // history starts at bottom of list again - especially as we may have discarded lines
  m_HistoryPosition = NULL;
  m_iHistoryStatus = eAtBottom;

  } // end of  CSendView::AddToCommandHistory 
Amended on Wed 04 Apr 2018 05:53 AM by Nick Gammon
USA Global Moderator #4
Nick, simple test case:

Run Hyperlink("test2", "info", "", "", "", 0) from your input bar using your defined script prefix.

Then, if Auto-repeat Command is enabled, press backspace to clear the input bar.

Then press up arrow. (to see that the hyperlink invocation is one line back)
Then press down arrow.

Then click on the hyperlink.
If you're connected to a server at the time, you may get a command not recognized message back.

Then press up arrow.
Then press up arrow again.

Note that before clicking the hyperlink, the command invocation is one line back, and that it is two lines back after clicking the hyperlink.

Then press down arrow as many times as you want.
Then press up arrow to see that the invocation is again one line back.
Amended on Wed 04 Apr 2018 02:09 PM by Fiendish
Australia Forum Administrator #5

Both of you were incorrect that an empty string was added to the command window, which is why I couldn’t reproduce it. After running your tests (clicking the hyperlink) I immediately pressed Ctrl+H to see the command history, and there was no extra, blank, command there, which then mysteriously disappeared later. :)

What was actually happening was that when you click on the output window, the focus moves to that part of the screen. You will notice that when you click on the output window the cursor stops flashing in the command window, because it no longer has the focus.

Certain actions, like ordinary typing, are designed to first put the focus back into the command window, which is why you probably don’t usually notice this.

See here for example:

/* If AllTypingToCommandWindow is enabled we redirect character messages to 
 * the bottom view. */

void CMUSHView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
  if (App.m_bAllTypingToCommandWindow) {
    OnKeysActivatecommandview();
    m_bottomview->SendMessage(WM_CHAR, nChar, nRepCnt | (nFlags << 16));
  } else
    CView::OnChar(nChar, nRepCnt, nFlags);
}

However the command window expects a special message (ID_KEYS_PREVCOMMAND, not WM_CHAR) in order to call the function which recalls the previous command, so that wasn’t acted on.

If you look carefully at your current version, when you press up-arrow after clicking on the hyperlink, the cursor starts flashing in the command window, so now pressing up-arrow recalls the previous command.

I’ve made a modification to force the focus back to the command window after clicking on a hyperlink (commit b9e52a1) which is available now from the pre-release page, see here.


This has been an interesting example of the X-Y Problem - both of you confidently reported that an extra entry was being inserted into the command window, something I couldn’t reproduce because I immediately pressed Ctrl+H to view the command window.

What the problem really was: After clicking on a hyperlink, pressing up-arrow to recall the previous command does not work. Or if you were really observant: After clicking on a hyperlink the focus does not return to the command window.

Amended on Wed 04 Apr 2018 09:12 PM by Nick Gammon
USA Global Moderator #6
Ooh, good eyes.