| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,7 +141,7 @@ class ReplHistory { | |||
| 141 | 141 | if (this[kHistory].length === 0 || this[kHistory][0] !== normalizedLine) { | |
| 142 | 142 | if (this[kRemoveHistoryDuplicates]) { | |
| 143 | 143 | // Remove older history line if identical to new one | |
| 144 | - const dupIndex = ArrayPrototypeIndexOf(this[kHistory], line); | ||
| 144 | + const dupIndex = ArrayPrototypeIndexOf(this[kHistory], normalizedLine); | ||
| 145 | 145 | if (dupIndex !== -1) ArrayPrototypeSplice(this[kHistory], dupIndex, 1); | |
| 146 | 146 | } | |
| 147 | 147 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + | ||
| 5 | + if (process.env.TERM === 'dumb') { | ||
| 6 | + common.skip('skipping - dumb terminal'); | ||
| 7 | + } | ||
| 8 | + | ||
| 9 | + const assert = require('assert'); | ||
| 10 | + const readline = require('readline'); | ||
| 11 | + const { EventEmitter } = require('events'); | ||
| 12 | + | ||
| 13 | + class FakeInput extends EventEmitter { | ||
| 14 | + resume() {} | ||
| 15 | + pause() {} | ||
| 16 | + write() {} | ||
| 17 | + end() {} | ||
| 18 | + } | ||
| 19 | + FakeInput.prototype.readable = true; | ||
| 20 | + | ||
| 21 | + { | ||
| 22 | + const fi = new FakeInput(); | ||
| 23 | + const rli = new readline.Interface({ | ||
| 24 | + input: fi, | ||
| 25 | + output: fi, | ||
| 26 | + terminal: true, | ||
| 27 | + removeHistoryDuplicates: true, | ||
| 28 | + }); | ||
| 29 | + | ||
| 30 | + function submitLine(line) { | ||
| 31 | + rli.line = line; | ||
| 32 | + fi.emit('keypress', '', { name: 'enter' }); | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + submitLine('line1\nline2'); | ||
| 36 | + submitLine('other'); | ||
| 37 | + submitLine('line1\nline2'); | ||
| 38 | + | ||
| 39 | + assert.strictEqual(rli.history.length, 2); | ||
| 40 | + assert.strictEqual(rli.history[0], 'line2\rline1'); | ||
| 41 | + assert.strictEqual(rli.history[1], 'other'); | ||
| 42 | + | ||
| 43 | + rli.close(); | ||
| 44 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments