Rainie3535 / sigil

Automatically exported from code.google.com/p/sigil
GNU General Public License v3.0
0 stars 0 forks source link

Text is deleted when replacing all in code view and all html with certain character #1222

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Open a new file and just type into book view "hello" with the quotes
Switch to  code view and open F&R
Set to Current File
Find: "
Replace: «
Replace All - works ok (except of course its now an invalid document as you'll 
see if you try to go to something in the book browser).

Now, repeat, except Set to All HTML Files
Replace All - text has disappeared (and its still invalid)

Likely that data is not well formed and forcing the change of files forces an 
attempt to auto clean?

Original issue reported on code.google.com by meme90...@gmail.com on 1 Feb 2012 at 7:21

GoogleCodeExporter commented 9 years ago
Changing Misc/SearchOperations SearchOperations::ReplaceHTMLInFile so the if 
statement is the following skips saving the bad files and leaves the text.  But 
we should show a dialog to warn the user that some files were skipped.

    if ( search_type == SearchOperations::CodeViewSearch )
    {
        const QString &text = CleanSource::PrettyPrint(
            XhtmlDoc::GetDomDocumentAsString( html_resource->GetDomDocumentForReading() ) );

        QString new_text;
        int count = 0;
        tie( new_text, count ) = PerformGlobalReplace( text, search_regex, replacement );

        // Check if the document is well-formed before saving it
        QString cleaned_new_text = CleanSource::ToValidXHTML( new_text );

        XhtmlDoc::WellFormedError error = XhtmlDoc::WellFormedErrorForSource( cleaned_new_text );
        bool well_formed = error.line == -1;

        if ( well_formed )
        {
            XhtmlDoc::LoadTextIntoDocument( cleaned_new_text );
            html_resource->SetDomDocument( XhtmlDoc::LoadTextIntoDocument( cleaned_new_text ) );
        }

        return count;
    }

Original comment by meme90...@gmail.com on 1 Feb 2012 at 7:53

GoogleCodeExporter commented 9 years ago
Showing a message about the issue is not feasible. I think it's worse to have 
replacements not made vs auto clean loosing data. EIther way the user will not 
get what they expect but if a replacement is not made then the user will be 
confused and think that Sigil is broken. They will then probably try the 
replacement a few more times and get frustrated.

Replace in all files is a blind replacement. The user is at the mercy of what 
happens.

The real fix is not to auto clean and have data removed. I plan on making this 
change as part of 0.6.

Original comment by john@nachtimwald.com on 2 Feb 2012 at 12:43

GoogleCodeExporter commented 9 years ago

Original comment by daveheil...@gmail.com on 19 May 2012 at 3:20