Schools just a week away from finishing and I have been working on Bespin. In my previous post I was able to get indent working on a selected piece of text. Now Julian had suggested that I change the code so that it would work on multiple lines.
First step was to grab all the selected lines:
![]()
*This gives us an array of selected lines which now contain the characters and the length of each line.
Great so we have the lines we would like to indent! Now next step was to iterate through each line and add an indent space in front of it. But of course the first line was special on its own since its start position could be selected from any column, unlike the lines afterward which would always retain their start position at column 0.
In order for me to add the indentation to any given line I would have to call the function “replaceCharacters(range,text_to_be_replaced_with)”. So therefore I would need to specify a range object which would point to that specific line. Here is how a range object looks like:

range = {
start: { row: 0, column: 13},
end: { row: 1, column: 24}
}
“start” position is where the selection starts and “end” is where the selection finishes. They both have “row” which specifies the line number and “column” which represents at which character.
Now since its a bit more clear let me show you my complete code..I’ll start from chunks:

@line 15, we will add indentation to the first line, and since “selection” already points to the first line we do not need to modify it.
Now we loop through each line and add 8 spaces of indentation. “current” identifies the row position where the first line is, since its not always 0!. Rest is self explanatory.

After the indentations have been added where needed, we need to reposition the cursor.
Here is the code

Complete source code:http://pastebin.com/Vi4RgscU
For now It does indent multiple lines, However it is not the final code. I will revisit the code and make a few minor modifications. I do have question regarding the tab spaces but I will get Julian to review my code. I doubt its 100% right but I am getting there…I’ll post more updates until then have a great weekend!
p.s When I got the new repository I realized the code was not in the text.js file anymore, it had been moved to a different file named editing.js under “commands” folder..