playground.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // basic playground for testing text editor while developing it
  2. const {
  3. ui: {
  4. Pane,
  5. form: {
  6. FocusElement
  7. }
  8. },
  9. util: {
  10. tuiApp
  11. }
  12. } = require('tui-lib')
  13. const TuiTextEditor = require('./index')
  14. const defaultText = `Hello, world!
  15. This is a test value.
  16. I think it is good fun.
  17. AWOO
  18. GAAA 1
  19. AAAA 2
  20. AAAA 3
  21. AAAA 4
  22. AAAA 5
  23. AAAA 6
  24. AAAA 7
  25. AAAA 8
  26. AAAA 9
  27. AAAA 10
  28. AAAA 11
  29. AAAA 12
  30. AAAA 13
  31. AAAA 14
  32. AAAA 15
  33. AAAA 16
  34. AAAA 17
  35. AAAA 18
  36. AAAA 19
  37. AAAA 20`
  38. class AppElement extends FocusElement {
  39. constructor() {
  40. super()
  41. this.pane = new Pane()
  42. this.addChild(this.pane)
  43. this.editor = new TuiTextEditor()
  44. this.pane.addChild(this.editor)
  45. this.editor.clearSourceAndLoadText(defaultText)
  46. }
  47. selected() {
  48. this.root.select(this.editor)
  49. }
  50. fixLayout() {
  51. this.fillParent()
  52. this.pane.fillParent()
  53. this.editor.fillParent()
  54. this.editor.fixLayout()
  55. }
  56. keyPressed(keyBuf) {
  57. if (keyBuf[0] === 0x03) {
  58. this.emit('quitRequested')
  59. } else if (keyBuf[0] === 0x07) {
  60. this.editor.showStatusMessage('You pressed ^G! Nice job! Random number: ' + Math.random())
  61. }
  62. }
  63. }
  64. tuiApp(({root, quitProgram}) => {
  65. const app = new AppElement()
  66. app.on('quitRequested', quitProgram)
  67. root.addChild(app)
  68. root.select(app)
  69. setTimeout(() => app.scheduleDrawWithoutPropertyChange())
  70. })