Stores a string in the history. @param str string to be stored @param oc old caret position @param nc new caret position
(final byte[] str, final int oc, final int nc)
| 107 | * @param nc new caret position |
| 108 | */ |
| 109 | public void store(final byte[] str, final int oc, final int nc) { |
| 110 | if(!active || str == hist[pos] || Token.eq(str, hist[pos])) return; |
| 111 | |
| 112 | // merge consecutive character inputs without deletions |
| 113 | int len = str.length; |
| 114 | if(pos > 0 && saved != pos && caret[pos] == oc && oc + 1 == nc && hist[pos - 1].length < len) { |
| 115 | hist[pos] = str; |
| 116 | caret[pos] = nc; |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | // summarize and limit size of new and existing entries |
| 121 | int off = pos + 1; |
| 122 | for(; off > 0 && len < MAXBYTES; off--) len += hist[off - 1].length; |
| 123 | // enough space: limit number of entries |
| 124 | if(off == 0 && pos + 1 == MAX) off = 1; |
| 125 | // remove entries |
| 126 | if(off > 0) { |
| 127 | Array.remove(hist, 0, off, MAX); |
| 128 | Array.remove(caret, 0, off, MAX); |
| 129 | saved -= off; |
| 130 | pos -= off; |
| 131 | } |
| 132 | // save new entry |
| 133 | if(pos >= 0) caret[pos] = oc; |
| 134 | if(saved > pos) saved = -1; |
| 135 | max = ++pos; |
| 136 | hist[pos] = str; |
| 137 | caret[pos] = nc; |
| 138 | // remove old entries to save memory |
| 139 | for(int p = pos + 1; p < MAX; p++) hist[p] = null; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Sets the saved position. |