Developing a legal IDE based on Atom
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.1 KiB

  1. const {SelectListView} = require('atom-space-pen-views')
  2. module.exports = class SuggestedDefinition extends SelectListView {
  3. constructor () {
  4. super()
  5. this.editor = null
  6. this.addClass('overlay from-top')
  7. this.panel = atom.workspace.addModalPanel({
  8. item: this.getElement(),
  9. visible: false
  10. })
  11. }
  12. viewForItem (item) {
  13. return `<li>${item}</li>`
  14. }
  15. confirmed (item) {
  16. this.hide()
  17. const position = this.editor.getCursorBufferPosition()
  18. const definition = `${item}_ `
  19. this.editor.insertText(definition)
  20. position.column = position.column + definition.length
  21. this.editor.setCursorBufferPosition(position)
  22. }
  23. cancelled () {
  24. this.hide()
  25. this.editor.component.didFocus()
  26. }
  27. // Returns an object that can be retrieved when package is activated
  28. serialize () {}
  29. // Tear down any state and detach
  30. destroy () {
  31. this.element.remove()
  32. }
  33. getElement () {
  34. return this.element
  35. }
  36. show (editor, items) {
  37. this.editor = editor
  38. this.setItems(items)
  39. this.panel.show()
  40. this.focusFilterEditor()
  41. }
  42. hide () {
  43. this.panel.hide()
  44. }
  45. }