bool ofxGuiInputField<Type>::keyPressed(ofKeyEventArgs & args){ if(hasFocus && !bMousePressed){ int newCursorIdx = -1; if(args.key >= '0' && args.key <= '9'){ int digit = args.key - '0'; newCursorIdx = insertKeystroke(ofToString(digit)); }else if(args.key == '.' ){ newCursorIdx = insertKeystroke("."); }else if(args.key == OF_KEY_BACKSPACE || args.key == OF_KEY_DEL){ if(hasSelectedText()){ input.erase(selectStartPos,selectEndPos-selectStartPos); newCursorIdx = selectStartPos; parseInput(); }else{ int deleteIdx = -1; if(args.key == OF_KEY_BACKSPACE){ deleteIdx = selectStartPos-1; }else if(args.key == OF_KEY_DEL){ deleteIdx = selectStartPos; } //erase char if valid deleteIdx if(deleteIdx >= 0 && deleteIdx < (int)input.size()){ input.erase(deleteIdx,1); newCursorIdx = deleteIdx; parseInput(); } } }else if(args.key == OF_KEY_LEFT){ if(hasSelectedText()){ newCursorIdx = selectStartPos; }else{ newCursorIdx = selectStartPos == 0 ? 0 : selectStartPos-1; } }else if(args.key == OF_KEY_RIGHT){ if(hasSelectedText()){ newCursorIdx = selectEndPos; }else{ newCursorIdx = selectStartPos == (int)input.size() ? (int)input.size() : selectStartPos+1; } }else if(args.key == OF_KEY_RETURN){ leaveFocus(); }else if((args.key >= '!' && args.key <= '~') || (args.key <= 'a' && args.key >= 'Z') || (args.key == ' ')){ newCursorIdx = insertAlphabetic(ofToString((char)args.key)); } if(newCursorIdx != -1){ //set cursor calculateSelectionArea(newCursorIdx,newCursorIdx); } return true; } return false; }
void RKConsole::doPopupMenu (const QPoint &pos) { RK_TRACE (APP); copy_action->setEnabled (hasSelectedText ()); copy_literal_action->setEnabled (hasSelectedText ()); run_selection_action->setEnabled (hasSelectedText ()); part->showPopupMenu (pos); run_selection_action->setEnabled (true); copy_literal_action->setEnabled (true); copy_action->setEnabled (true); }
void QsciEditor::showCustomMenu( const QPoint &position ) { contextMenu.clear(); QMenu formatMenu( "&Format" ); formatMenu.addAction( changeFontAct ); if ( hasSelectedText() ) formatMenu.addAction( toggleCaseAct ); contextMenu.addMenu( &formatMenu ); contextMenu.addSeparator(); if ( hasSelectedText() ) { contextMenu.addAction( cutAct ); contextMenu.addAction( copyAct ); } if ( SendScintilla( SCI_CANPASTE ) ) contextMenu.addAction( pasteAct ); if ( hasSelectedText() ) contextMenu.addAction( deleteAct ); if ( not text().isEmpty() or hasSelectedText() ) contextMenu.addSeparator(); if ( not text().isEmpty() ) contextMenu.addAction( selectAct ); if ( hasSelectedText() ) contextMenu.addAction( deselectAct ); if ( isUndoAvailable() or isRedoAvailable() ) contextMenu.addSeparator(); if ( isUndoAvailable() ) contextMenu.addAction( undoAct ); if ( isRedoAvailable() ) contextMenu.addAction( redoAct ); if ( not text().isEmpty() ) { contextMenu.addSeparator(); contextMenu.addAction( searchAct ); contextMenu.addAction( replaceAct ); } contextMenu.exec( QWidget::mapToGlobal( position ) ); };
void TextEdit::keyPressEvent(QKeyEvent *e) { if (((e->key() == Key_Enter) || (e->key() == Key_Return))){ if (!m_bCtrlMode || (e->state() & ControlButton)){ emit ctrlEnterPressed(); return; } } if (!isReadOnly()){ if ((e->state() == ShiftButton) && (e->key() == Key_Insert)){ paste(); return; } if ((e->state() == ControlButton) && (e->key() == Key_Delete)){ cut(); return; } } #if (COMPAT_QT_VERSION >= 0x030000) && (COMPAT_QT_VERSION < 0x030100) // Workaround about autoformat feature in qt 3.0.x if ((e->text()[0] == '-') || (e->text()[0] == '*')){ if (isOverwriteMode() && !hasSelectedText()) moveCursor(MoveForward, true); insert( e->text(), TRUE, FALSE ); return; } #endif // Note: We no longer translate Enter to Ctrl-Enter since we need // to know about paragraph breaks now. TextShow::keyPressEvent(e); }
/** * Returns HTML markup for selected text. If no text is selected, returns * HTML markup for all text. */ QString PsiTextView::getHtml() const { PsiTextView *ptv = (PsiTextView *)this; QTextCursor cursor = ptv->textCursor(); int position = ptv->verticalScrollBar()->value(); bool unselectAll = false; if (!hasSelectedText()) { ptv->selectAll(); unselectAll = true; } QMimeData *mime = createMimeDataFromSelection(); QString result = mime->html(); delete mime; // we need to restore original position if selectAll() // was called, because setTextCursor() (which is necessary // to clear selection) will move vertical scroll bar if (unselectAll) { cursor.clearSelection(); ptv->setTextCursor(cursor); ptv->verticalScrollBar()->setValue(position); } return result; }
//VOXOX CHANGE by Rolando - 2009.05.11 - method called when lineedit lost focus void VoxOxToolTipLineEdit::leaveEvent ( QEvent * event ){ if (QLineEdit::text() == _toolTip || QLineEdit::text().isEmpty()) {//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is equal to tooltip or is empty displayToolTipMessage(); } else{ int cursorPositionValue = cursorPosition();//VOXOX CHANGE by Rolando - 2009.06.02 - gets current Cursor Position int intSelectedStart = -1; QString stringText; if(hasSelectedText()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is selected text stringText = selectedText();//VOXOX CHANGE by Rolando - 2009.06.02 - gets selected text intSelectedStart = selectionStart();//VOXOX CHANGE by Rolando - 2009.06.02 - gets position where selection starts } if(_message == QLineEdit::text()){//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is equal to _message then sets _shortMessage QLineEdit::setText(_shortMessage); } else{//VOXOX CHANGE by Rolando - 2009.05.11 - if current text is not equal to _message then updates _shortMessage and _message and then sets _shortMessage as current text updateMessageText(QLineEdit::text()); QLineEdit::setText(_shortMessage); } //VOXOX CHANGE by Rolando - 2009.10.13 if(intSelectedStart >= 0 && intSelectedStart + stringText.length() <= getMaximumCharsAllowed()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is a text selected setSelection(intSelectedStart, stringText.length());//VOXOX CHANGE by Rolando - 2009.06.02 - as we set the long message in lineedit, we need to set the text was selected } currentTextChanged(text()); } QLineEdit::leaveEvent(event); //changeFocusToParent();//VOXOX CHANGE by Rolando - 2009.05.22 - method to send focus to another widget when mouse leaves the lineedit }
void SLineEdit::contextMenuEvent(QContextMenuEvent *event) { bool selection = hasSelectedText(); bool ro = isReadOnly(); QMenu menu(this); if (selection && !ro) menu.addAction(SCHAT_ICON(EditCut), tr("Cut"), this, SLOT(cut())); if (selection) menu.addAction(SCHAT_ICON(EditCopy), tr("Copy"), this, SLOT(cut())); if (!ro && !QApplication::clipboard()->text().isEmpty()) menu.addAction(SCHAT_ICON(EditPaste), tr("Paste"), this, SLOT(paste())); if (selection && !ro) menu.addAction(SCHAT_ICON(Remove), tr("Delete"), this, SLOT(deleteSelected())); if (!menu.isEmpty()) menu.addSeparator(); if (!text().isEmpty() && text() != selectedText()) menu.addAction(SCHAT_ICON(EditSelectAll), tr("Select All"), this, SLOT(selectAll())); if (!menu.isEmpty()) menu.exec(event->globalPos()); }
/** * Returns a symbol for automatic selection. * If any text is selected in the editor, it is returned. Otherwise, the method * returns the word on which the cursor is currently positioned. * @return The current text */ QString Editor::currentSymbol() const { // Return any selected text. // TODO: Should we test for a valid symbol here to? if (hasSelectedText()) return QsciScintilla::selectedText(); // No selected text. // Get the boundaries of the word from the current cursor position. long pos, start, end; pos = SendScintilla(SCI_GETCURRENTPOS); start = SendScintilla(SCI_WORDSTARTPOSITION, pos, 0L); end = SendScintilla(SCI_WORDENDPOSITION, pos, 0L); // Return an empty string if no word is found. if (start >= end) return QString(); // Extract the word's text using its position boundaries. QByteArray curText; curText.resize(end - start ); SendScintilla(SCI_GETTEXTRANGE, start, end, curText.data()); // NOTE: Scintilla's definition of a "word" does not correspond to a // "symbol". Make sure the result contains only alpha-numeric characters // or an underscore. QString symbol(curText); if (!QRegExp("\\w+").exactMatch(symbol)) return QString(); return symbol; }
void *MsgView::processEvent(Event *e) { if ((e->type() == EventSent) || (e->type() == EventMessageReceived)){ Message *msg = (Message*)(e->param()); if (msg->contact() != m_id) return NULL; if (msg->getFlags() & MESSAGE_NOVIEW) return NULL; bool bAdd = true; if (msg->type() == MessageStatus){ bAdd = false; Contact *contact = getContacts()->contact(msg->contact()); if (contact){ CoreUserData *data = (CoreUserData*)(contact->getUserData(CorePlugin::m_plugin->user_data_id)); if (data && data->LogStatus.bValue) bAdd = true; } } if (bAdd && (e->type() == EventMessageReceived)){ Contact *contact = getContacts()->contact(msg->contact()); if (contact){ CoreUserData *data = (CoreUserData*)(contact->getUserData(CorePlugin::m_plugin->user_data_id)); if (data->OpenNewMessage.bValue) bAdd = false; } } if (bAdd){ addMessage(msg); if (!hasSelectedText()) scrollToBottom(); } } return MsgViewBase::processEvent(e); }
void QsciEditor::pasteAction() { if ( hasSelectedText() ) removeSelectedText(); SendScintilla( SCI_PASTE ); };
void SciDoc::moveDown() { if ( int_->curEdit_ == NULL ) return; if ( hasSelectedText() ) { int line1, line2, col1, col2; getSelection(line1, col1, line2, col2); int realLine2 = line2; if ( col2 == 0 ) --line2; if ( line2 == lineCount() - 1 ) return; int_->curEdit_->beginUndoAction(); for (int line = line2 + 1; line >= line1 + 1; --line) { int_->curEdit_->setCursorPosition(line, 0); swapLines(); } setSelection(line1 + 1, col1, realLine2 + 1, col2); int_->curEdit_->endUndoAction(); } else { int line, col; int_->curEdit_->getCursorPosition(&line, &col); if ( line < lineCount() - 1 ) { int_->curEdit_->setCursorPosition(line + 1, 0); swapLines(); int_->curEdit_->setCursorPosition(line + 1, col); } } }
void QsciEditor::toggleCase() { int lF, iF, lT, iT; getSelection( &lF, &iF, &lT, &iT ); if ( not hasSelectedText() ) return; QString txt = selectedText(); QString newTxt; bool caps = true; Q_FOREACH( QChar ch, txt ) if ( ch.isLetter() ) caps &= ch.isUpper(); if ( caps ) newTxt = txt.toLower(); else newTxt = txt.toUpper(); removeSelectedText(); insert( newTxt ); setSelection( lF, iF, lT, iT ); };
void ShortcutLineEdit::keyPressEvent(QKeyEvent *e) { int nextKey = e->key(); if ( keys.count() > 3 || // too long shortcut nextKey == Qt::Key_Control || // dont count modifier keys nextKey == Qt::Key_Shift || nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt ) return; // applying current modifiers to key nextKey |= getModifiers(e->modifiers(), e->text()); // If there is selected text, replace *all* instead of appending. if (hasSelectedText()) { keys.clear(); } keys.append(nextKey); // set displaying information setText(getKeySequence().toString(QKeySequence::NativeText)); emit contentsChanged(); // not call QLineEdit's event because we already changed contents e->accept(); }
int QHexView::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QAbstractScrollArea::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: setShowAddress((*reinterpret_cast< bool(*)>(_a[1]))); break; case 1: setShowAsciiDump((*reinterpret_cast< bool(*)>(_a[1]))); break; case 2: setShowHexDump((*reinterpret_cast< bool(*)>(_a[1]))); break; case 3: setShowComments((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: setWordWidth((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: setRowWidth((*reinterpret_cast< int(*)>(_a[1]))); break; case 6: setFont((*reinterpret_cast< const QFont(*)>(_a[1]))); break; case 7: setShowAddressSeparator((*reinterpret_cast< bool(*)>(_a[1]))); break; case 8: repaint(); break; case 9: clear(); break; case 10: selectAll(); break; case 11: deselect(); break; case 12: { bool _r = hasSelectedText(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 13: mnuSetFont(); break; case 14: mnuCopy(); break; default: ; } _id -= 15; } return _id; }
void SciDoc::moveUp() { if ( int_->curEdit_ == NULL ) return; if ( hasSelectedText() ) { int line1, line2, col1, col2; getSelection(line1, col1, line2, col2); if ( line1 == 0 ) return; int realLine2 = line2; if ( col2 == 0 ) --line2; int_->curEdit_->beginUndoAction(); for (int line = line1; line <= line2; ++line) { int_->curEdit_->setCursorPosition(line, 0); swapLines(); } setSelection(line1 - 1, col1, realLine2 - 1, col2); int_->curEdit_->endUndoAction(); } else { int line, col; int_->curEdit_->getCursorPosition(&line, &col); if ( line > 0 ) { swapLines(); int_->curEdit_->setCursorPosition(line - 1, col); } } }
void VoxOxToolTipLineEdit::keyPressEvent(QKeyEvent * event) { if (!_cleared) { clearLineEdit(); repaintPrimaryColor(); } if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter) {//if key pressed was return or enter if(!QLineEdit::text().isEmpty()){ updateMessageText(QLineEdit::text()); QLineEdit::setText(_shortMessage); currentTextChanged(text()); } QLineEdit::keyPressEvent(event); changeFocusToParent();//VOXOX CHANGE by Rolando - 2009.05.22 - method to send focus to another widget when mouse leaves the lineedit } else{//if key pressed was not return or enter key int cursorPositionValue = cursorPosition();//VOXOX CHANGE by Rolando - 2009.06.02 - gets current Cursor Position bool isShortMessage = QLineEdit::text() == _shortMessage;//VOXOX CHANGE by Rolando - 2009.06.02 - we need to check if current text is equal to _shortMessage int intSelectedStart = -1; QString text; if(hasSelectedText()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is selected text text = selectedText();//VOXOX CHANGE by Rolando - 2009.06.02 - gets selected text intSelectedStart = selectionStart();//VOXOX CHANGE by Rolando - 2009.06.02 - gets position where selection starts } QLineEdit::setText(_message);//VOXOX CHANGE by Rolando - 2009.06.02 - sets long message if(intSelectedStart >= 0){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is a text selected setSelection(intSelectedStart, text.length());//VOXOX CHANGE by Rolando - 2009.06.02 - as we set the long message in lineedit, we need to set the text was selected } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if there is not a text selected if(isShortMessage){//VOXOX CHANGE by Rolando - 2009.06.02 - if we had currentText equal to _shortMessage //VOXOX CHANGE by Rolando - 2009.10.13 if(cursorPositionValue == _shortMessage.length()){//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is the rightest pos allowed setCursorPosition(_message.length());//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to rightest position after we changed the current text by _message } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed } } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if we had not currentText equal to _shortMessage setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to old position + 1 } } QLineEdit::keyPressEvent(event);//processes event - it should be processed before update _shortMessage and _message variables updateMessageText(QLineEdit::text());//VOXOX CHANGE by Rolando - 2009.06.02 - we update the short and long messages } keyPressedSignal(event->key()); }
int QLabel::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QFrame::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 12) qt_static_metacall(this, _c, _id, _a); _id -= 12; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = text(); break; case 1: *reinterpret_cast< Qt::TextFormat*>(_v) = textFormat(); break; case 2: _a[0] = const_cast<void*>(reinterpret_cast<const void*>(pixmap())); break; case 3: *reinterpret_cast< bool*>(_v) = hasScaledContents(); break; case 4: *reinterpret_cast< Qt::Alignment*>(_v) = alignment(); break; case 5: *reinterpret_cast< bool*>(_v) = wordWrap(); break; case 6: *reinterpret_cast< int*>(_v) = margin(); break; case 7: *reinterpret_cast< int*>(_v) = indent(); break; case 8: *reinterpret_cast< bool*>(_v) = openExternalLinks(); break; case 9: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 10: *reinterpret_cast< bool*>(_v) = hasSelectedText(); break; case 11: *reinterpret_cast< QString*>(_v) = selectedText(); break; } _id -= 12; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setText(*reinterpret_cast< QString*>(_v)); break; case 1: setTextFormat(*reinterpret_cast< Qt::TextFormat*>(_v)); break; case 2: setPixmap(*reinterpret_cast< QPixmap*>(_v)); break; case 3: setScaledContents(*reinterpret_cast< bool*>(_v)); break; case 4: setAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break; case 5: setWordWrap(*reinterpret_cast< bool*>(_v)); break; case 6: setMargin(*reinterpret_cast< int*>(_v)); break; case 7: setIndent(*reinterpret_cast< int*>(_v)); break; case 8: setOpenExternalLinks(*reinterpret_cast< bool*>(_v)); break; case 9: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; } _id -= 12; } else if (_c == QMetaObject::ResetProperty) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 12; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 12; } #endif // QT_NO_PROPERTIES return _id; }
int ofxGuiInputField<Type>::insertKeystroke(const std::string & character){ if(hasSelectedText()){ input.erase(selectStartPos,selectEndPos-selectStartPos); } input.insert(selectStartPos,character); parseInput(); return selectStartPos + 1; }
void LineEditWidget::clearSelectAllOnRelease() { if (m_shouldSelectAllOnRelease && hasSelectedText()) { disconnect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelectAllOnRelease())); m_shouldSelectAllOnRelease = false; } }
void LineEditWidget::copyToNote() { const QString note(hasSelectedText() ? selectedText() : text()); if (!note.isEmpty()) { NotesManager::addNote(BookmarksModel::UrlBookmark, QUrl(), note); } }
void TextShow::cut() { if (isReadOnly()) return; if (hasSelectedText()) { copy(); removeSelectedText(); } }
/** Remove any existing auto completion suggestion */ void HintingLineEdit::clearSuggestion() { if (!hasSelectedText()) return; // Carefully cut out the selected text QString line = text(); line = line.left(selectionStart()) + line.mid(selectionStart() + selectedText().length()); setText(line); }
void SonicPiScintilla::downcaseWordOrSelection(){ if(hasSelectedText()) { SendScintilla(SCI_LOWERCASE); } else { setMark(); SendScintilla(SCI_WORDRIGHT); SendScintilla(SCI_LOWERCASE); deselect(); } }
void LineEdit::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { if (!hasSelectedText()) selectAll(); } QLineEdit::mouseReleaseEvent(event); }
QPopupMenu *CInnoDBStatus::createPopupMenu(const QPoint &) { QPopupMenu *menu = new QPopupMenu(this); int copy_id = menu->insertItem(getPixmapIcon("copyIcon"), tr("&Copy"), this, SLOT(copy())); menu->setItemEnabled(copy_id, hasSelectedText()); menu->insertSeparator(); menu->insertItem(getPixmapIcon("saveIcon"), tr("&Save"), this, SLOT(save())); menu->insertSeparator(); menu->insertItem(getPixmapIcon("refreshIcon"), tr("&Refresh"), this, SLOT(refresh())); return menu; }
void KJotsEdit::openUrl() { if (hasSelectedText()) { KURL url(selectedText()); if(url.isValid()) { new KRun(url); } } }
void TextShow::viewportMousePressEvent(QMouseEvent *e) { if ((e->button() == RightButton) && hasSelectedText()){ if (menu == NULL){ menu = new QPopupMenu(this); menu->insertItem(Icon("editcopy"), i18n("&Copy"), this, SLOT(copy()), 0, 1); } menu->popup(e->globalPos()); return; } QTextBrowser::viewportMousePressEvent(e); }
void InputBox::contextMenuEvent(QContextMenuEvent *event) { QMenu *const menu = new QMenu(this); menu->addAction(tr("&Copy"), this, SLOT(copy()))->setEnabled(hasSelectedText()); menu->addSeparator(); menu->addAction(tr("&Select All"), this, SLOT(selectAll()))->setEnabled(!displayText().isEmpty()); menu->addSeparator(); menu->addAction(tr("C&lear"), this, SLOT(clearData()))->setEnabled(getData().value != NULL_VALUE); menu->exec(event->globalPos()); delete menu; }
QTextDrag *TextShow::dragObject(QWidget *parent) const { if (!hasSelectedText()) return NULL; #if (COMPAT_QT_VERSION < 0x030000) || (COMPAT_QT_VERSION >= 0x030100) if (textFormat() == RichText){ RichTextDrag *drag = new RichTextDrag(parent); drag->setRichText(selectedText()); return drag; } #endif return new QTextDrag(selectedText(), parent ); }
void SonicPiScintilla::moveLineOrSelection(int numLines) { beginUndoAction(); int linenum, cursor, origLinenum, origCursor; getCursorPosition(&linenum, &cursor); origLinenum = linenum; origCursor = cursor; bool hadSelectedText = hasSelectedText(); if(!hadSelectedText) { setSelection(linenum, 0, linenum + 1, 0); } int lineFrom, indexFrom, lineTo, indexTo, lineOffset; getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo); lineOffset = lineTo - origLinenum; linenum = lineFrom; QString selection = selectedText(); if(selection[selection.length()-1] != '\n') { selection = selection + "\n"; lineTo += 1; lineOffset += 1; indexTo = 0; replaceSelectedText(""); setCursorPosition(linenum, 0); SendScintilla(SCI_DELETEBACK); } else { replaceSelectedText(""); } setCursorPosition(linenum, 0); moveLines(numLines); getCursorPosition(&linenum, &cursor); setCursorPosition(linenum, 0); insert(selection); setCursorPosition(linenum + lineOffset, origCursor); int diffLine = lineTo - lineFrom; int diffIndex = indexTo - indexFrom; setSelection(linenum + diffLine, diffIndex, linenum, 0); endUndoAction(); }