Menu

#36 don't add duplicates to history

open
nobody
5
2007-09-07
2007-09-07
Derek Baum
No

a line is not added to history if it is identical to the previous line.

if you repeatedly enter a sequence of lines, then the history contains many duplicate entries, that make it difficult to find previous entries.

For example, I use jline when testing an application and repeatedly enter the sequence line1, line2, line3; Then I run another test and repeatedly enter line2, line4, line6.

If I now want to revert to the first test, line1 and line 3 are way up the history list because it is filled with duplicates of line2, line 4, line 6.

This is actually very easy to fix:

Currently History.addToHistory() only checks whether the new buffer is a duplicate of the last line; Instead it needs to check whether the current line appears anywhere in the history, and if it does remove the old history entry and add the new one.

This is all achieved by adding single line of code to addHistory():

history.remove(buffer);

I attach a patch containing this fix.

derek.baum@paremus.com

Discussion

  • Derek Baum

    Derek Baum - 2007-09-07

    patch to History.java to avoid adding duplicate entries

     
  • Charles Oliver Nutter

    I'm confused whether this is actually a bug. I did something like

    line1
    line2
    line3
    line2
    line4

    And going back through history, it matches it exactly. If what you want is to have it avoid adding items that appear anywhere in history, that seems to be different behavior from a typical shell, where all lines you've entered in will come back in the history (including duplicate lines, in fact).

    I don't think removing lines from history is what most people would want, so perhaps this needs to be configurable?

     
  • Derek Baum

    Derek Baum - 2010-05-14

    > I don't think removing lines from history is what most people would want,
    so perhaps this needs to be configurable?

    configurable would be fine.

    Note: there are multiple forks of jiine on github, including http://github.com/gnodet/jline

     

Log in to post a comment.