Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. diff --git a/public/js/components/EditorSearchBar.js b/public/js/components/EditorSearchBar.js
  2. index cecba60..cbb740e 100644
  3. --- a/public/js/components/EditorSearchBar.js
  4. +++ b/public/js/components/EditorSearchBar.js
  5. @@ -5,6 +5,7 @@ const Svg = require("./utils/Svg");
  6. const { isEnabled } = require("devtools-config");
  7. const { find, findNext, findPrev } = require("../utils/source-search");
  8. const classnames = require("classnames");
  9. +const debounce = require("lodash.debounce");
  10.  
  11. require("./EditorSearchBar.css");
  12.  
  13. @@ -92,25 +93,37 @@ const EditorSearchBar = React.createClass({
  14. },
  15.  
  16. onKeyUp(e) {
  17. - const ed = this.props.editor;
  18. - const ctx = { ed, cm: ed.codeMirror };
  19. - const { query, index, count } = this.state;
  20. -
  21. if (e.key != "Enter") {
  22. return;
  23. }
  24.  
  25. if (e.shiftKey) {
  26. - findPrev(ctx, query);
  27. - const nextIndex = index == 0 ? count - 1 : index - 1;
  28. - this.setState({ index: nextIndex });
  29. + this.searchNext();
  30. } else {
  31. - findNext(ctx, query);
  32. - const nextIndex = index == count - 1 ? 0 : index + 1;
  33. - this.setState({ index: nextIndex });
  34. + this.searchPrev();
  35. }
  36. },
  37.  
  38. + searchNext: debounce(function() {
  39. + const ed = this.props.editor;
  40. + const ctx = { ed, cm: ed.codeMirror };
  41. + const { query, index, count } = this.state;
  42. +
  43. + findNext(ctx, query);
  44. + const nextIndex = index == count - 1 ? 0 : index + 1;
  45. + this.setState({ index: nextIndex });
  46. + }),
  47. +
  48. + searchPrev: debounce(function() {
  49. + const ed = this.props.editor;
  50. + const ctx = { ed, cm: ed.codeMirror };
  51. + const { query, index, count } = this.state;
  52. +
  53. + findPrev(ctx, query);
  54. + const nextIndex = index == 0 ? count - 1 : index - 1;
  55. + this.setState({ index: nextIndex });
  56. + }),
  57. +
  58. renderSummary() {
  59. const { count, index, query } = this.state;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement