Ticket #6885: textview_paste_26102011.patch

File textview_paste_26102011.patch, 2.3 KB (added by hamish, 13 years ago)
  • src/kits/interface/TextView.cpp

     
    14471447                    B_MIME_TYPE, (const void **)&runArray, &runLen);
    14481448            }
    14491449
     1450            _FilterDisallowedChars((char*)text, len, runArray);
     1451
     1452            if (len < 1) {
     1453                beep();
     1454                clipboard->Unlock();
     1455                return;
     1456            }
     1457
    14501458            if (fUndo) {
    14511459                delete fUndo;
    14521460                fUndo = new PasteUndoBuffer(this, text, len, runArray,
     
    48054813            inMessage->FindData("application/x-vnd.Be-text_run_array",
    48064814                B_MIME_TYPE, (const void **)&runArray, &runLen);
    48074815
     4816        _FilterDisallowedChars((char*)text, dataLen, runArray);
     4817
     4818        if (dataLen < 1) {
     4819            beep();
     4820            return true;
     4821        }
     4822
    48084823        if (fUndo) {
    48094824            delete fUndo;
    48104825            fUndo = new DropUndoBuffer(this, text, dataLen, runArray,
     
    55745589    int32 start;
    55755590    int32 finish;
    55765591    GetSelection(&start, &finish);
    5577    
     5592
    55785593    bool canEdit = IsEditable();
    55795594    int32 length = TextLength();
    55805595
     
    56025617    menu->Go(where, true, true, true);
    56035618}
    56045619
     5620
     5621void
     5622BTextView::_FilterDisallowedChars(char* text, int32& len,
     5623    text_run_array* runArray)
     5624{
     5625    if (!fDisallowedChars)
     5626        return;
     5627
     5628    if (fDisallowedChars->IsEmpty() || !text)
     5629        return;
     5630
     5631    int32 s = 0;
     5632    if (runArray) {
     5633        int32 remNext = 0;
     5634
     5635        for (int i = 0; i < runArray->count; i++) {
     5636            runArray->runs[i].offset -= remNext;
     5637            while (s < runArray->runs[i].offset && s < len) {
     5638                if (fDisallowedChars->HasItem((void*)text[s])) {
     5639                    memmove(text + s, text + s + 1, len - s - 1);
     5640                    len--;
     5641                    runArray->runs[i].offset--;
     5642                    remNext++;
     5643                } else
     5644                    s++;
     5645            }
     5646        }
     5647    }
     5648
     5649    while (s < len) {
     5650        if (fDisallowedChars->HasItem((void*)text[s])) {
     5651            memmove(text + s, text + s + 1, len - s - 1);
     5652            len--;
     5653        } else
     5654            s++;
     5655    }
     5656}
     5657
    56055658// #pragma mark - BTextView::TextTrackState
    56065659
    56075660
  • headers/os/interface/TextView.h

     
    411411
    412412            void                _ShowContextMenu(BPoint where);
    413413
     414            void                _FilterDisallowedChars(char* text, int32& len,
     415                                    text_run_array* runArray);
     416
    414417private:
    415418            BPrivate::TextGapBuffer*    fText;
    416419            LineBuffer*         fLines;