Github user benkeen commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/204#discussion_r22274509
  
    --- Diff: app/addons/documents/views-doceditor.js ---
    @@ -529,13 +454,160 @@ function (app, FauxtonAPI, Components, Documents, 
Databases, prettify) {
               showHideEditDocString(event);
             });
     
    +        // place focus on the editor
    +        editor.editor.focus();
    +
           }.bind(this));
    +
    +      // this sucks having to reference #dashboard, but when user clicks 
in the region below the editor I want it
    +      // to focus on the final line. It feels natural that way
    +      $('.scrollable').on('click', function(e) {
    +        var clickedInEditor = $(e.target).closest('#editor-container');
    +        if (clickedInEditor.length === 0) {
    +          editor.editor.focus();
    +          var session = editor.editor.getSession();
    +          var count = session.getLength();
    +          editor.editor.gotoLine(count, session.getLine(count-1).length);
    +        }
    +      });
    +    },
    +
    +    serialize: function () {
    +      return {
    +        doc: this.model,
    +        attachments: this.getAttachments()
    +      };
    +    },
    +
    +    getAttachments: function () {
    +      var attachments = this.model.get('_attachments');
    +      if (!attachments) { return false; }
    +
    +      return _.map(attachments, function (att, key) {
    +        return {
    +          fileName: key,
    +          size: att.length,
    +          contentType: att.content_type,
    +          url: this.model.url() + '/' + app.utils.safeURLName(key)
    +        };
    +      }, this);
    +    },
    +
    +    determineStringEditMatch: function (event) {
    +      var selStart = this.editor.getSelectionStart().row;
    +      var selEnd = this.editor.getSelectionEnd().row;
    +
    +      // one JS(ON) string can't span more than one line - we edit one 
string, so ensure we don't select several lines
    +      if (selStart >=0 && selEnd >= 0 && selStart === selEnd && 
this.editor.isRowExpanded(selStart)) {
    +        var editLine = this.editor.getLine(selStart),
    +            editMatch = editLine.match(/^([ \t]*)(["|'][a-zA-Z0-9_]*["|']: 
)?(["|'].*["|'],?[ \t]*)$/);
    +
    +        if (editMatch) {
    +          return editMatch;
    +        }
    +      }
    +      return null;
    +    },
    +
    +    showHideEditDocString: function (event) {
    +      this.$('button.string-edit').attr('disabled', 'true');
    +      if (!this.hasValidCode()) {
    +        return false;
    +      }
    +      var editMatch = this.determineStringEditMatch(event);
    +      if (editMatch) {
    +        this.$('button.string-edit').removeAttr('disabled');
    +        /* remove the following line (along with CSS) to go back to the 
toolbar: take the offset top of the editor, go down as many lines as we are 
positioned including fold and adjust by two pixels as the button is slightly 
larger than a line */
    +        var positionFromTop = (this.$('#editor-container').offset().top - 
2 + this.editor.getRowHeight() * 
this.editor.documentToScreenRow(this.editor.getSelectionStart().row)) - 62;
    +        this.$('button.string-edit').css('top', positionFromTop + 'px');
    +        return true;
    +      }
    +      return false;
    +    },
    +
    +    stringEditing: function (event) {
    +      event.preventDefault();
    +      if (!this.hasValidCode()) {
    +        return;
    +      }
    +      var editMatch = this.determineStringEditMatch(event);
    +      if (editMatch) {
    +        var indent = editMatch[1] || '',
    +          hashKey = editMatch[2] || '',
    +          editText = editMatch[3],
    +          comma = '';
    +        if (editText.substring(editText.length - 1) === ',') {
    +          editText = editText.substring(0, editText.length - 1);
    +          comma = ',';
    +        }
    +        this.stringEditModal.openWin(this.editor, indent, hashKey, 
editText, comma);
    +      }
         },
     
         cleanup: function () {
    -      if (this.editor) this.editor.remove();
    +      this.editor && this.editor.remove();
    +      $('#dashboard').off('click');
         }
       });
     
    +
    +  Views.StringEditModal = Components.ModalView.extend({
    +    template: 'addons/documents/templates/string_edit_modal',
    +
    +    initialize: function () {
    +      _.bindAll(this);
    --- End diff --
    
    This was old code I didn't touch. It can probably be removed, I'll check.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to