Esempio n. 1
0
/**
 * Returns the current position of the cursor.
 * @param	nLine	Holds the line on which the cursor is currently located
 * @param	nCol	Holds the column on which the cursor is currently located
 * @return	true if successful, false otherwise (cursor interface was not
 *			obtained)
 */
bool EditorPage::getCursorPos(uint& nLine, uint& nCol)
{
    int line, col;
	// Get the cursor position (adjusted to 1-based counting)
	const KTextEditor::Cursor c = m_pView->cursorPosition();
    c.position(line, col);
    nLine = line;
    nCol = col;
	nLine++;
	nCol++;
	
	return true;
}
Esempio n. 2
0
// TODO: will be a word in two lines ?
QString EditorPage::getWordUnderCursor(uint* pPosInWord)
{
	QString sLine;
	int nLine, nCol, nFrom, nTo, nLast, nLength;
	QChar ch;

	const KTextEditor::Cursor c = m_pView->cursorPosition();

	// Get the line on which the cursor is positioned
    c.position(nLine, nCol);
    const KTextEditor::Cursor cFrom(nLine, 0);
    const KTextEditor::Cursor cTo = m_pDoc->endOfLine(nLine);
    KTextEditor::Range range(cFrom, cTo);

    sLine = m_pDoc->text(range);
	
	// Find the beginning of the current word
	for (nFrom = nCol; nFrom > 0;) {
		ch = sLine.at(nFrom - 1);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nFrom--;
	}
	
	// Find the end of the current word
	nLast = sLine.length();
	for (nTo = nCol; nTo < nLast;) {
		ch = sLine.at(nTo);
		if (!ch.isLetter() && !ch.isDigit() && ch != '_')
			break;
		
		nTo++;
	}

	// Mark empty words
	nLength = nTo - nFrom;
	if (nLength == 0)
		return QString::null;
	
	// Return the in-word position, if required
	if (pPosInWord != NULL)
		*pPosInWord = nCol - nFrom;
	
	// Extract the word under the cursor from the entire line
	return sLine.mid(nFrom, nLength);
}
Esempio n. 3
0
/**
 * Handles changes in the cursor position.
 * Emits a signal with the new line and column numbers.
 */
void EditorPage::slotCursorPosChange(KTextEditor::View *view, 
        const KTextEditor::Cursor &newPosition)
{
	int nLine, nCol;

    if (view == NULL)
        return;

	// Find the new line and column number, and emit the signal
    newPosition.position(nLine, nCol);
    nLine++;
    nCol++;

	emit cursorPosChanged(nLine, nCol);
	
	// Select the relevant symbol in the tag list
	if (Config().getAutoTagHl() && (m_nLine != nLine)) {
		m_pCtagsListWidget->gotoLine(nLine);
		m_nLine = nLine;
	}
    m_pView->setFocus();
}