Testing, if you need to test something this is the place

Posted on
Page
of 36
  • Test

  • Test 2


    1 Attachment

    • IMG_20160612_140435.jpg
  • test


    1 Attachment

    • test.jpg
  • test


    1 Attachment

    • test.png
  • test


    1 Attachment

    • kittens.jpg
  • test


    1 Attachment

    • 20160626_153016 (1).jpg
  • .

  • test

  • Come on Imgur. Work dammit!!!

  • test


    1 Attachment

    • image1.JPG
  • Test

  • Alright... thinking aloud:

    core/templates/conversation.html has this JS at the bottom:

    	$('#post-a-reply-handle').on('click',function(e){
    		var selectedText = Comments.prototype.getWindowSelectedText();
    		if (selectedText){
    			replyBox.textarea.value = selectedText;
    			replyBox.quote();
    		}
    	});
    

    Which then calls:
    core/static/js/simpleEditor.js

        simpleEditor.prototype.quote = function(){
          this.textarea.value = this.formattedTextWith("> %s");
        };
    

    Which in turn calls (same file):

        simpleEditor.prototype.formattedTextWith = function(tag){
    
          var selection = this.getSelectionDetailsObject();
    
          var newText = selection.start.text +
                        this.applyFormatting(selection.selected.text, tag) +
                        selection.end.text;
    
          return newText;
        };
    

    And applyFormatting looks like:

        simpleEditor.prototype.applyFormatting = function(text, tag){
    
          // splits text into array by newlines and applies tag to each index of array.
          var selectedTextFragments = text.split(/\n/g);
          for(var i=0,j=selectedTextFragments.length;i<j;i++){
              selectedTextFragments[i] = tag.replace(/%s/g, selectedTextFragments[i]);
          }
    
          var formattedText = selectedTextFragments.join('\n');
    
          return formattedText;
        };
    

    I don't understand applyFormatting, and am not sure what this.getSelectionDetailsObject() returns.

    Ah... getSelectionDetailsObject is a local this. reference, so that's in this file too:

        simpleEditor.prototype.getSelectionDetailsObject = function(){
    
    
          var text           = this.textarea.value,
              startPos       = this.textarea.selectionStart,
              endPos         = this.textarea.selectionEnd,
              selectedLength = this.textarea.selectionEnd-this.textarea.selectionStart;
    
          var startText     = text.substr(0,startPos),
              selectedText  = text.substr(startPos,selectedLength),
              endText       = text.substr(endPos,text.length);
    
          var retval = {
            start     : {
              position : startPos,
              text     : startText
            },
            end       : {
              position : endPos,
              text     : endText
            },
            selected  : {
              length   : selectedLength,
              text     : selectedText
            }
          };
    
          return retval;
    
        };
    

    I'll look into whether that does sane things later on.

    As I don't understand applyFormatting in relation to quote I will probably seek to fix by just making another version of quote to be used for new messages as quote seems to work intra-message... and this only really has issues when the selection is outside of the text box.

    Actually... maybe that's the bug... the selection is outside the textbox and so it gets confused as when quote is called there is no set of selection attributes on the textarea, which it looks like getSelectionDetailsObject needs.

    Yeah... that's the bug.

    Cool.

    I'll think of the fix after the meeting and journey home.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Testing, if you need to test something this is the place

Posted by Avatar for Velocio @Velocio

Actions