Ejemplo n.º 1
0
YCursor YLineSearch::forwardBefore(const QString& ch, bool& found, unsigned int times)
{
    YCursor pos = forward(ch, found, times);

    if(found) {
        pos.setX(pos.x() - 1);
    }

    updateHistory(ch, SearchForwardBefore);
    return pos;
}
Ejemplo n.º 2
0
YCursor YLineSearch::reverseAfter(const QString& ch, bool& found, unsigned int times)
{
    YCursor pos = reverse(ch, found, times);

    if(found) {
        pos.setX(pos.x() + 1);
    }

    updateHistory(ch, SearchBackwardAfter);
    return pos;
}
Ejemplo n.º 3
0
CmdState YModeInsert::deleteChar(const YCommandArgs &args)
{
    dbg() << HERE() << endl ;
    YCursor cur = args.view->getLinePositionCursor();
    YBuffer* mBuffer = args.view->buffer();

    if(cur.x() == mBuffer->textline(cur.y()).length()) {
        if(args.view->getLocalStringOption("backspace").contains("eol")) {
            mBuffer->action()->mergeNextLine(args.view, cur.y(), false);
        }
    } else {
        mBuffer->action()->deleteChar(args.view, cur, 1);
    }

    return CmdOk;
}
Ejemplo n.º 4
0
void NYView::guiDrawCell(YCursor pos, const YDrawCell& cell)
{
    int x = pos.x();

    if(!fakeLine) {
        /* if this line is a fake, don't apply margins */
        x += marginLeft;
    }

    /*
     * TODO: reverse bg/fg... but... how set bg ?
    if ( cell.sel & YSelectionPool::Visual ) {
     }
     */
    int mAttributes = attribWhite;

    if(cell.foregroundColor().isValid()) {
        int rawcolor = cell.foregroundColor().rgb() & RGB_MASK;

        if(mAttributesMap.contains(rawcolor)) {
            mAttributes = mAttributesMap[ rawcolor ];
        } else {
            yzWarning() << "Unknown color from libyzis, cell.foregroundColor().name() is " << cell.foregroundColor().name() << endl;
        }
    }

    if(cell.hasSelection(yzis::SelectionAny)) {
        mAttributes |= A_REVERSE;  // TODO, reverse bg/fg
    }

    //if ( drawUnderline() ) mAttributes |= A_UNDERLINE;
    /* convert string to wide_char */
    QByteArray my_char = cell.content().toLocal8Bit();
    char* from_char = new char[ my_char.length() + 1 ];
    strcpy(from_char, my_char.constData());
    size_t needed = mbstowcs(NULL, from_char, strlen(from_char)) + 1;
    wchar_t* wide_char = (wchar_t*)malloc(needed * sizeof(wchar_t));
    mbstowcs(wide_char, from_char, strlen(from_char));
    wide_char[needed - 1] = '\0';
    wattron(editor, mAttributes);
    mvwaddwstr(editor, pos.y(), x, wide_char);
    wattroff(editor, mAttributes);
    free(wide_char);
    delete[] from_char;
}
Ejemplo n.º 5
0
void NYView::guiDrawClearToEOL(YCursor pos, const YDrawCell& cell)
{
    QChar clearChar = cell.content()[0]; /* TODO */
    int x = pos.x();

    if(!fakeLine) {
        x += marginLeft;
    }

    if(clearChar.isSpace()) {
        /* optimization */
        wmove(editor, pos.y(), x);
        wclrtoeol(editor);
    } else {
        QString erase;
        erase.fill(clearChar, width - x);
        mvwaddstr(editor, pos.y(), x, erase.toLocal8Bit().constData());
    }
}
Ejemplo n.º 6
0
int YDrawBufferAbstractIterator::getCut() {
	int cut = 0;
	if ( mPos.line() == mI.toPos().line() ) {
		YCursor end = mI.openedEndCursor();
		YDrawCell cell = mDrawBuffer->mContent[mCurBLine][mCurLine][mCurCell];
		int w = 0;
		switch ( mIntervalType ) {
			case yzis::ScreenInterval :
				w = cell.width();
				break;
			case yzis::BufferInterval :
				w = cell.length();
				break;
		}
		w -= mPosShift;
		if ( mPos.column() + w >= end.column() ) {
			cut = end.column() - mPos.column();
		}
	}
	return cut;
}
Ejemplo n.º 7
0
void YModeInsert::imCompose(YView* mView, const QString& entry)
{
    if(!m_imPreedit.isEmpty()) {    // replace current one
        YCursor pos = mView->getLinePositionCursor();
        int len = m_imPreedit.length();

        if(pos.x() >= len) {
            pos.setX(pos.x() - len);
        } else {
            pos.setX(0);
        }

        mView->buffer()->action()->replaceText(mView, pos, len, entry);
    } else {
        YKey input;
        input.fromString(entry);
        YSession::self()->sendKey(mView, input);
    }

    m_imPreedit = entry;
}
Ejemplo n.º 8
0
YCursor YLineSearch::forward(const QString& ch, bool& found, unsigned int times)
{
    YCursor cur = mView->getLineColumnCursor();
    int x = cur.x() + 1; // Start search after cursor pos
    int y = cur.y();
    const QString& current = mView->buffer()->textline(y);
    int index = 0;
    unsigned int nfound = 0;

    while(nfound < times && x < current.length()) {
        index = current.indexOf(ch, x);

        if(index < 0) {
            break;
        }

        x = index + 1;
        nfound++;
    }

    YCursor pos;
    found = (nfound == times);

    if(found) {
        pos.setX(x - 1);
        pos.setY(y);
    }

    updateHistory(ch, SearchForward);
    return pos;
}
Ejemplo n.º 9
0
CmdState YModeInsert::commandEnter(const YCommandArgs &args)
{
    YCursor cur = args.view->getLinePositionCursor();
    YBuffer* mBuffer = args.view->buffer();

    if(args.view->getLocalBooleanOption("cindent")) {
        args.view->indent();
    } else {
        mBuffer->action()->insertNewLine(args.view, cur);
        QStringList results = YSession::self()->eventCall("INDENT_ON_ENTER", args.view);

        if(results.count() > 0) {
            if(results[0].length() != 0) {
                mBuffer->action()->replaceLine(args.view, cur.y() + 1, results[0] + mBuffer->textline(cur.y() + 1).trimmed());
                args.view->gotoLinePosition(cur.y() + 1, results[0].length());
            }
        }
    }

    args.view->stickToColumn();
    return CmdOk;
}
Ejemplo n.º 10
0
CmdState YModeInsert::backspace(const YCommandArgs &args)
{
    YCursor cur = args.view->getLinePositionCursor();
    YBuffer* mBuffer = args.view->buffer();

    if(cur.x() == 0 && cur.y() > 0 && args.view->getLocalStringOption("backspace").contains("eol")) {
        mBuffer->action()->mergeNextLine(args.view, cur.y() - 1);
        //mBuffer->action()->deleteChar( mView, *mView->getLinePositionCursor(), 1 ); see bug #158
    } else if(cur.x() > 0) {
        mBuffer->action()->deleteChar(args.view, cur.x() - 1, cur.y(), 1);
    }

    return CmdOk;
}
Ejemplo n.º 11
0
CmdState YModeInsert::deleteWordBefore(const YCommandArgs &args)
{
    YCursor cur = args.view->getLinePositionCursor();
    YBuffer* mBuffer = args.view->buffer();

    if(cur.x() == 0 && cur.y() > 0 && args.view->getLocalStringOption("backspace").contains("eol")) {
        mBuffer->action()->mergeNextLine(args.view, cur.y() - 1);
        //mBuffer->action()->deleteChar( mView, *mView->getLinePositionCursor(), 1 ); see bug #158
    } else {
        QString line = mBuffer->textline(cur.y());
        QChar tmp;
        bool isWord;
        int x = cur.x();

        // delete whitespace characters preceding current word
        while(x > 0 && line[x - 1].isSpace()) {
            --x;
        }

        // delete a word or set of not-word not-whitespace characters
        if(x > 0) {
            tmp = line[x - 1];
            isWord = tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark();

            // delete word behind the cursor (if there is one)
            if(isWord)
                while(isWord && --x > 0) {
                    tmp = line[x - 1];
                    isWord = (tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark());
                }
            // otherwise, delete all not-word and not-whitespace
            // characters behind the cursor
            else
                while(!isWord && !tmp.isSpace() && --x > 0) {
                    tmp = line[x - 1];
                    isWord = (tmp.isLetterOrNumber() || tmp == '_' || tmp.isMark());
                }
        }

        //do it
        mBuffer->action()->deleteChar(args.view, x, cur.y(), cur.x() - x);
    }

    return CmdOk;
}
Ejemplo n.º 12
0
void YDrawBufferAbstractIterator::setup( const YInterval& i, yzis::IntervalType itype )
{
	mI = i;
	mIntervalType = itype;
	mStopped = false;

	YCursor start = i.closedStartCursor();
	bool found = false;
	switch ( mIntervalType ) {
		case yzis::ScreenInterval :
			found = mDrawBuffer->targetScreenLine(start.line(), &mCurBLine, &mCurLine);
			break;
		case yzis::BufferInterval :
			found = mDrawBuffer->targetBufferLine(start.line(), &mCurBLine);
			break;
	}
	if ( !found ) {
		mStopped = true;
	} else {
		mPos = start;
		mPosShift = 0;
		switch ( mIntervalType ) {
			case yzis::ScreenInterval :
				found = (start.column() == mDrawBuffer->targetScreenColumn(start.column(), mCurBLine, mCurLine, &mCurCell, &mPosShift));
				break;
			case yzis::BufferInterval :
				found = (start.column() == mDrawBuffer->targetBufferColumn(start.column(), mCurBLine, &mCurLine, &mCurCell, &mPosShift));
				break;
		}
		if ( found ) {
			setupCell(getCut());
		} else {
			setupEOLCell();
		}
	}
}
Ejemplo n.º 13
0
YCursor YLineSearch::reverse(const QString& ch, bool& found, unsigned int times)
{
    YCursor cur = mView->getLineColumnCursor();
    unsigned int x = cur.x();
    unsigned int y = cur.y();

    if(x) {
        x--;    // Start search before current cursor
    }

    const QString& current = mView->buffer()->textline(y);
    int index = 0;
    unsigned int nfound = 0;

    while(nfound < times && x > 0) {
        index = current.lastIndexOf(ch, x);

        if(index < 0) {
            break;
        }

        x = index - 1;
        nfound++;
    }

    YCursor pos;
    found = (nfound == times);

    if(found) {
        pos.setX(x + 1);
        pos.setY(y);
    }

    updateHistory(ch, SearchBackward);
    return pos;
}
Ejemplo n.º 14
0
void NYView::drawCursor()
{
    YCursor pos = getRowColumnCursor();
    wmove(editor, pos.line(), pos.column() + marginLeft);
    wrefresh(editor);
}
Ejemplo n.º 15
0
CmdState YModeSearch::execCommand(YView* view, const YKeySequence& keys, YKeySequence::const_iterator &parsePos)
{
    Q_UNUSED(keys);
    //XXX YSelection* searchSelection = view->getSelectionPool()->search();

    if(*parsePos == Qt::Key_Enter || *parsePos == Qt::Key_Return) {
        QString what = view->guiGetCommandLineText();
        dbg() << "Current search: " << what;
        bool found = false;
        YCursor pos;

        if(what.isEmpty()) {
            pos = replaySearch(view, &found);
        } else {
            mHistory->addEntry(what);
            pos = search(view, what, &found);

            if(view->getLocalBooleanOption("incsearch") && incSearchFound) {
                pos = incSearchResult;
                incSearchFound = false;
            }
        }

        if(found) {
            view->gotoLinePosition(pos.y() , pos.x());
        } else {
            view->displayInfo(_("Pattern not found: ") + what);
        }

        view->modePool()->pop();
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == Qt::Key_Down) {
        mHistory->goForwardInTime();
        view->guiSetCommandLineText(mHistory->getEntry());
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == Qt::Key_Left || *parsePos == Qt::Key_Right) {
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == Qt::Key_Up) {
        mHistory->goBackInTime();
        view->guiSetCommandLineText(mHistory->getEntry());
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == YKey(Qt::Key_Colon, Qt::AltModifier)) {
        view->modePool()->change(ModeEx);
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == Qt::Key_Escape
              || *parsePos == YKey(Qt::Key_C, Qt::ControlModifier)) {
        if(view->getLocalBooleanOption("incsearch")) {
            view->gotoLinePosition(mSearchBegin.y(), mSearchBegin.x());
            view->setPaintAutoCommit(false);
            incSearchFound = false;
            //view->sendXXXPaintEvent( searchSelection->map() );
            //XXX searchSelection->clear();
            view->commitPaintEvent();
        }

        view->modePool()->pop();
        ++parsePos;
        return CmdOk;
    } else if(*parsePos == Qt::Key_Backspace) {
        QString back = view->guiGetCommandLineText();

        if(back.isEmpty()) {
            view->modePool()->pop();
            ++parsePos;
            return CmdOk;
        }

        view->guiSetCommandLineText(back.remove(back.length() - 1, 1));
    } else {
        view->guiSetCommandLineText(view->guiGetCommandLineText() + parsePos->toString());
    }

    if(view->getLocalBooleanOption("incsearch")) {
        view->setPaintAutoCommit(false);
        int matchlength;
        incSearchResult = search(view, view->guiGetCommandLineText(), mSearchBegin, &matchlength, &(incSearchFound));

        if(incSearchFound) {
            if(view->getLocalBooleanOption("hlsearch")) {
                YCursor endResult(incSearchResult);
                endResult.setX(endResult.x() + matchlength - 1);
                //XXX  searchSelection->addInterval( YInterval(incSearchResult, endResult) );
                //view->sendXXXPaintEvent( searchSelection->map() );
            }

            view->gotoLinePositionAndStick(incSearchResult);
        } else {
            view->gotoLinePosition(mSearchBegin.y() , mSearchBegin.x());
            //view->sendXXXPaintEvent( searchSelection->map() );
            //XXX searchSelection->clear();
        }

        view->commitPaintEvent();
    }

    ++parsePos;
    return CmdOk;
}