Re: Problem with Indenting and lists:Text pasted from Word document

  •  07-20-2010, 6:20 PM

    Re: Problem with Indenting and lists:Text pasted from Word document

    This is still an issue and I really needed this so I wrote something that overwrites the list commands.  Works pretty well i think although i'm sure i can improve on it since its a little bit of a hack. :)
     
    So .. we all know for most users, BR is going to be the preferred break element as it's a lot more intuitive for users that don't know HTML standards .. and I DO think it should be implemented or at least an option do have this behavior.  Let me know if this ever does :)  With that said, you can use this .. works ok for me.
     
    ------------------------------
    function CuteEditor_OnCommand(editor,command,ui,value)   
     {   
        if (command=="InsertUnorderedList"){
            
            var selectedText = getSelectedHTML(editor);
            
            if (selectedText!=""){        
                editor.PasteHTML("<ul><li>"+selectedText+"</li></ul>");        
            } else{
            
                //create some temp text
                var tempTEXT="‰";
                
                //lets insert some temp text where our cursor is
                editor.PasteHTML(tempTEXT);
                
                //put our new html into a var and define some other vars
                var editorText=editor.getHTML();
                var editorTextToBR="";
                var startOfText="";
                var endOfText="";
                
                //get the index of the pasted text and use that to where we are entering the bullet
                var cursorPos=editorText.indexOf(tempTEXT, 0);
                
                //Lets find the index of the next breaking character BR/P/DIV in that order
                var nextBRPos=getNextBRPos(editorText,cursorPos);

                //lets define the start of the text, start of the text to the temp char
                startOfText=editorText.substring(0,cursorPos);
                
                //lets define whats going onto the bullet            
                editorTextToBR=editorText.substring(cursorPos,nextBRPos).replace(tempTEXT,"");
                
                //lets define the rest of the document text starting from after the bullet text                      
                endOfText=editorText.substring(nextBRPos,editorText.length);
                
                //lets now put all 3 components together and set our text
                editor.setHTML(startOfText+"<ul><li>"+editorTextToBR+"</li></ul>"+endOfText);
          }        
          return true;
       } else if (command=="InsertOrderedList"){
            
            var selectedText = getSelectedHTML(editor);
            
            if (selectedText!=""){        
                editor.PasteHTML("<ol><li>"+selectedText+"</li></ol>");        
            } else{
            
                //create some temp text
                var tempTEXT="‰";
                
                //lets insert some temp text where our cursor is
                editor.PasteHTML(tempTEXT);
                
                //put our new html into a var and define some other vars
                var editorText=editor.getHTML();
                var editorTextToBR="";
                var startOfText="";
                var endOfText="";
                
                //get the index of the pasted text and use that to where we are entering the bullet
                var cursorPos=editorText.indexOf(tempTEXT, 0);
                
                //Lets find the index of the next breaking character BR/P/DIV in that order
                var nextBRPos=getNextBRPos(editorText,cursorPos);

                //lets define the start of the text, start of the text to the temp char
                startOfText=editorText.substring(0,cursorPos);
                
                //lets define whats going onto the bullet            
                editorTextToBR=editorText.substring(cursorPos,nextBRPos).replace(tempTEXT,"");
                
                //lets define the rest of the document text starting from after the bullet text                      
                endOfText=editorText.substring(nextBRPos,editorText.length);
                
                //lets now put all 3 components together and set our text
                editor.setHTML(startOfText+"<ol><li>"+editorTextToBR+"</li></ol>"+endOfText);
          }        
          return true;
       }
    }

    function getNextBRPos(myText,startingAtPos){
        
        //lets find the index of the next paragraph
        //break whatever it is
        //and return it's position
        var posBR = myText.indexOf("<br />", startingAtPos);    //get the index of the next BR
        var posP = myText.indexOf("</p>", startingAtPos);       //get the index of the next P
        var posDIV = myText.indexOf("</div>", startingAtPos);   //get the index of the next DIV
        
        if (posBR>0){return posBR;}
        else if(posP>0){return posP;}
        else if(posDIV>0){return posDIV;}
        else{return myText.length;}
    }
     ------------------------------
     
    Cheers
View Complete Thread