Exemplo n.º 1
0
int EBuffer::MoveNextEqualIndent() {
    int L = VToR(CP.Row);
    int I = LineIndented(L);

    while (L++ < RCount - 1)
        if ((RLine(L)->Count > 0) && (LineIndented(L) == I))
            return SetPosR(I, L);
    return 0;
}
Exemplo n.º 2
0
int EBuffer::MovePrevEqualIndent() {
    int L = VToR(CP.Row);
    int I = LineIndented(L);

    while (--L >= 0)
        if ((RLine(L)->Count > 0) && (LineIndented(L) == I))
            return SetPosR(I, L);
    return 0;
}
Exemplo n.º 3
0
int EBuffer::IndentLine(int Row, int Indent) {
    int I, C;
    int Ind = Indent;

    if (Row < 0) return 0;
    if (Row >= RCount) return 0;
    if (Indent < 0) Indent = 0;
    I = LineIndented(Row);
    if (Indent != I) {
        if (I > 0)
            if (DelText(Row, 0, I) == 0) return 0;
        if (Indent > 0) {
            C = 0;
            if (BFI(this, BFI_IndentWithTabs)) {
                char ch = 9;

                while (BFI(this, BFI_TabSize) <= Indent) {
                    if (InsText(Row, C, 1, &ch) == 0) return 0;
                    Indent -= BFI(this, BFI_TabSize);
                    C += BFI(this, BFI_TabSize);
                }
            }
            if (Indent > 0)
                if (InsText(Row, C, Indent, 0) == 0) return 0;
        }
    }
    return Ind - I;
}
Exemplo n.º 4
0
int EBuffer::BlockUnindent() {
    EPoint B, E;
    int L;

    AutoExtend = 0;
    if (CheckBlock() == 0) return 0;
    if (RCount <= 0) return 0;
    B = BB;
    E = BE;
    Draw(B.Row, E.Row);
    if (SetPosR(B.Col, B.Row) == 0) return 0;
    for (L = B.Row; L <= E.Row; L++) {
        switch (BlockMode) {
        case bmStream:
        case bmLine:
            if (L < E.Row || E.Col != 0) {
                int I = LineIndented(L) - 1;
                if (I >= 0)
                    IndentLine(L, I);
            }
            break;
        case bmColumn:
            if (L < E.Row) {
                if (InsText(L, E.Col, 1, 0) == 0) return 0;
                if (DelText(L, B.Col, 1) == 0) return 0;
            }
            break;
        }
    }
    if (SetPosR(B.Col, B.Row) == 0) return 0;
    return 1;
}
Exemplo n.º 5
0
int EBuffer::LineCenter() {
    if (LineTrim() == 0)
        return 0;
    int ind = LineIndented(VToR(CP.Row));
    int left = BFI(this, BFI_LeftMargin);
    int right = BFI(this, BFI_RightMargin);
    int len = LineLen();

    //int chs = len - ind;
    int newind = left + ((right - left) - (len - ind)) / 2;
    if (newind < left)
        newind = left;
    return IndentLine(VToR(CP.Row), newind);
}
Exemplo n.º 6
0
int EBuffer::BackSpace() {
    int Y = VToR(CP.Row);

    if (CheckBlock() == 1 && BFI(this, BFI_BackSpKillBlock)) {
        if (BlockKill() == 0)
            return 0;
    } else if (BFI(this, BFI_WordWrap) == 2 && CP.Row > 0 && !IsLineBlank(Y - 1) &&
               CP.Col <= BFI(this, BFI_LeftMargin) && CP.Col <= LineIndented(Y)) {
        if (SetPos(LineLen(Y - 1), CP.Row - 1) == 0) return 0;
    } else if (CP.Col == 0) {
        if (CP.Row > 0)
            if (ExposeRow(VToR(CP.Row) - 1) == 0) return 0;
        if (MoveUp() == 0) return 0;
        if (MoveLineEnd() == 0) return 0;
        if (LineJoin() == 0) return 0;
    } else {
        if (BFI(this, BFI_BackSpUnindents) && (LineIndented(Y) == CP.Col)) {
            int C = CP.Col, C1 = 0;
            int L = VToR(CP.Row);

            C1 = C;
            while (L > 0 && (IsLineBlank(L - 1) || (C1 = LineIndented(L - 1)) >= C)) L--;
            if (L == 0) C1 = 0;
            if (C1 == C) C1--;
            if (C1 < 0) C1 = 0;
            if (C1 > C) C1 = C;
            if (SetPos(C1, CP.Row) == 0) return 0;
            if (C > LineIndented(Y)) return 0;
            if (DelText(Y, C1, C - C1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, C1, 1, " ") == 0) return 0;
        } else if (BFI(this, BFI_BackSpKillTab)) {
            int P;
            int C = CP.Col, C1;

            P = CharOffset(RLine(Y), C - 1);
            C1 = ScreenPos(RLine(Y), P);
            if (SetPos(C1, CP.Row) == 0) return 0;
            if (DelText(Y, C1, C - C1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, C1, 1, " ") == 0) return 0;
        } else {
            if (MovePrev() == 0) return 0;

            ELine *L = RLine(Y);
            int C = CharOffset(L, CP.Col);

            if (L->Count > 0 && L->Chars[C] == 9) {
                /* We're on top of tab character. Skip over all spaces and
                   tabs so that only the last space/tab gets deleted. */
                while (C < L->Count &&
                        (L->Chars[C+1] == 9 || L->Chars[C+1] == ' ')) C++;
            }

            if (DelText(Y, ScreenPos(L, C), 1) == 0) return 0;
            if (BFI(this, BFI_Insert) == 0)
                if (InsText(Y, ScreenPos(L, C), 1, " ") == 0) return 0;
        }
    }
    if (BFI(this, BFI_WordWrap) == 2) {
        if (DoWrap(0) == 0) return 0;
    }
    if (BFI(this, BFI_Trim)) {
        Y = VToR(CP.Row);
        if (TrimLine(Y) == 0) return 0;
    }
    return 1;
}
Exemplo n.º 7
0
int EBuffer::DoWrap(int WrapAll) {
    int L, Len, C, P, Ind;
    PELine LP;
    int Left = BFI(this, BFI_LeftMargin), Right = BFI(this, BFI_RightMargin);
    int FirstParaLine;
    int NoChange = 0, NoChangeX = 0;

    if (Left >= Right) return 0;

    L = VToR(CP.Row);

    FirstParaLine = 0;
    if (L > 0)
        if (IsLineBlank(L - 1)) FirstParaLine = L;

    while (L < RCount) {
        NoChange = 1;

        if (VToR(CP.Row) != L || L != FirstParaLine) {
            if (VToR(CP.Row) == L)
                if (CP.Col <= LineIndented(L))
                    if (SetPos(Left, CP.Row) == 0) WFAIL(1);
            Ind = IndentLine(L, Left);
            if (VToR(CP.Row) == L)
                if (SetPos((CP.Col + Ind > 0) ? CP.Col + Ind : 0, CP.Row) == 0) WFAIL(2);
            NoChange = 0;
        }
        Len = LineLen(L);

        if (IsLineBlank(L)) break;

        if (Len < Right) {
            int firstwordbeg = -1;
            int firstwordend = -1;
            int X;
            PELine lp;

            if (L < RCount - 1) {
                IndentLine(L + 1, 0);
                if ((ScreenPos(RLine(L + 1), RLine(L + 1)->Count) == 0) ||
                        (RLine(L + 1)->Chars[0] == '>') || (RLine(L + 1)->Chars[0] == '<')) break;
            } else
                break;
            if (L + 1 >= RCount) break;

            lp = RLine(L + 1);
            for (X = 0; X < lp->Count; X++) {
                if (firstwordbeg == -1 &&
                        ((lp->Chars[X] != ' ') && (lp->Chars[X] != '\t'))) {
                    firstwordbeg = X;
                } else if (firstwordend == -1 &&
                           ((lp->Chars[X] == ' ' || lp->Chars[X] == '\t'))) {
                    firstwordend = X - 1;
                }
            }
            if (firstwordbeg != -1)
                if (firstwordend == -1)
                    firstwordend = lp->Count;

            if (firstwordend == -1) break;
            if (Right - Len > firstwordend - firstwordbeg) {
                if (JoinLine(L, Len + 1) == 0) WFAIL(3);
                NoChange = 0;
                continue;
            } else
                IndentLine(L + 1, Left);
        } else if (Len > Right) {
            C = Right;
            P = CharOffset(LP = RLine(L), C);
            while ((C > Left) &&
                    ((LP->Chars[P] != ' ') &&
                     (LP->Chars[P] != 9)))
                C = ScreenPos(LP, --P);

            if (P <= Left) {
                L++;
                continue;
            }
            C = ScreenPos(LP, P);
            if (SplitLine(L, C) == 0) WFAIL(4);
            IndentLine(L + 1, Left);
            if (L < RCount - 2 && LineLen(L + 1) == Left) {
                if (!IsLineBlank(L + 2)) {
                    if (JoinLine(L + 1, Left) == 0) WFAIL(5);
                }
            }
            if (L == VToR(CP.Row) && CP.Col > C) {
                if (SetPos(Left + CP.Col - C - 1, CP.Row + 1) == 0) WFAIL(6);
            }
            NoChange = 0;
            L++;
            continue;
        }
        if (WrapAll == 0)
            if (NoChangeX) {
                //printf("\n\nBreak OUT = %d\n\x7", L);
                break;
            }
        L++;
        NoChangeX = NoChange;
    }
    if (WrapAll == 1)
        if (SetPosR(Left,
                    (L < RCount - 2) ? (L + 2) :
                    (L < RCount - 1) ? (L + 1) :
                    (RCount - 1)) == 0) WFAIL(7);
    return 1;
}