Skip to content

Commit

Permalink
Merge pull request #609 from oskarhane/3.0-no-repeat-history
Browse files Browse the repository at this point in the history
Don't add repeated executed commands to history
  • Loading branch information
pe4cey authored Jun 29, 2017
2 parents 046e06c + 745ec30 commit acdbe18
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/shared/modules/history/historyDuck.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export const ADD = 'history/ADD'
export const getHistory = (state) => state[NAME]

function addHistoryHelper (state, newState, maxHistory) {
let newHistory = [].concat(state)
// If it's the same as the last entry, don't add it
if (state && state.length && state[0] === newState) {
return state
}
let newHistory = [...state]
newHistory.unshift(newState)
return newHistory.slice(0, maxHistory)
}
Expand Down
20 changes: 19 additions & 1 deletion src/shared/modules/history/historyDuck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* global test, expect */
/* global describe, test, expect */
import reducer, * as actions from './historyDuck'

describe('editor reducer', () => {
Expand All @@ -32,6 +32,24 @@ describe('editor reducer', () => {
const nextnextState = reducer(nextState, historyAction)
expect(nextnextState).toEqual([':history', ':help'])
})
test('editor.actionTypes.ADD_HISTORY does not repeat two entries in a row', () => {
// Given
const helpAction = actions.addHistory(':help', 20)
const historyAction = actions.addHistory(':history', 20)
const initalState = [':help']

// When
const nextState = reducer(initalState, helpAction)

// Then
expect(nextState).toEqual([':help'])

// When
const nextState1 = reducer(nextState, historyAction)

// Then
expect(nextState1).toEqual([':history', ':help'])
})

test('takes editor.actionTypes.SET_MAX_HISTORY into account', () => {
const initalState = [
Expand Down

0 comments on commit acdbe18

Please sign in to comment.