void Screen::writeSelectionToStream(TerminalCharacterDecoder* decoder , bool preserveLineBreaks) { // do nothing if selection is invalid if ( !isSelectionValid() ) return; int top = sel_TL / columns; int left = sel_TL % columns; int bottom = sel_BR / columns; int right = sel_BR % columns; Q_ASSERT( top >= 0 && left >= 0 && bottom >= 0 && right >= 0 ); //kDebug() << "sel_TL = " << sel_TL; //kDebug() << "columns = " << columns; for (int y=top;y<=bottom;y++) { int start = 0; if ( y == top || columnmode ) start = left; int count = -1; if ( y == bottom || columnmode ) count = right - start + 1; const bool appendNewLine = ( y != bottom ); copyLineToStream( y, start, count, decoder, appendNewLine, preserveLineBreaks ); } }
void Screen::writeToStream(TerminalCharacterDecoder* decoder, int startIndex, int endIndex, bool preserveLineBreaks) const { int top = startIndex / columns; int left = startIndex % columns; int bottom = endIndex / columns; int right = endIndex % columns; Q_ASSERT( top >= 0 && left >= 0 && bottom >= 0 && right >= 0 ); for (int y=top;y<=bottom;y++) { int start = 0; if ( y == top || blockSelectionMode ) start = left; int count = -1; if ( y == bottom || blockSelectionMode ) count = right - start + 1; const bool appendNewLine = ( y != bottom ); int copied = copyLineToStream( y, start, count, decoder, appendNewLine, preserveLineBreaks ); // if the selection goes beyond the end of the last line then // append a new line character. // // this makes it possible to 'select' a trailing new line character after // the text on a line. if ( y == bottom && copied < count ) { Character newLineChar('\n'); decoder->decodeLine(&newLineChar,1,0); } } }