put max step length in constant
This commit is contained in:
parent
abde8b45d2
commit
07b2e51dce
2 changed files with 5 additions and 5 deletions
|
@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
export const MAX_STEP_LENGTH = 10;
|
||||||
|
|
||||||
export default class HistoryManager {
|
export default class HistoryManager {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._stack = [];
|
this._stack = [];
|
||||||
|
@ -30,9 +32,8 @@ export default class HistoryManager {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (diff.added) {
|
if (diff.added) {
|
||||||
// only append after every 5th keystroke while typing
|
|
||||||
this._newlyTypedCharCount += diff.added.length;
|
this._newlyTypedCharCount += diff.added.length;
|
||||||
return this._newlyTypedCharCount > 5;
|
return this._newlyTypedCharCount > MAX_STEP_LENGTH;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -15,7 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import expect from 'expect';
|
import expect from 'expect';
|
||||||
import HistoryManager from "../../src/editor/history";
|
import HistoryManager, {MAX_STEP_LENGTH} from "../../src/editor/history";
|
||||||
|
|
||||||
describe('editor/history', function() {
|
describe('editor/history', function() {
|
||||||
it('push, then undo', function() {
|
it('push, then undo', function() {
|
||||||
|
@ -77,8 +77,7 @@ describe('editor/history', function() {
|
||||||
expect(undoState.caret).toEqual(firstCaret);
|
expect(undoState.caret).toEqual(firstCaret);
|
||||||
expect(undoState.parts).toEqual(["hello"]);
|
expect(undoState.parts).toEqual(["hello"]);
|
||||||
expect(history.canUndo()).toEqual(false);
|
expect(history.canUndo()).toEqual(false);
|
||||||
expect(keystrokeCount).toBeGreaterThan(2);
|
expect(keystrokeCount).toEqual(MAX_STEP_LENGTH + 1); // +1 before we type before checking
|
||||||
expect(keystrokeCount).toBeLessThan(20);
|
|
||||||
});
|
});
|
||||||
it('keystroke that didn\'t add a step can undo', function() {
|
it('keystroke that didn\'t add a step can undo', function() {
|
||||||
const history = new HistoryManager();
|
const history = new HistoryManager();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue