Skip to content

Commit 6e8e0f7

Browse files
committed
Fix snippet info preview bug for ANSI encodings
When either the plain text or Markdown file types were selected in the Save Snippet Information dialogue box and the ANSI encoding was also selected, the snippet displayed when the output ws previewed could differ from that written to file. This occured when the snippet contained characters that couldn't be rendered correctly in ANSI: the preview would show the correct snippet (rendered in Unicode) while the snippet with incorrectly translated characters was written to file. This bug was fixed so that the snippet previewed was also in ANSI encoding, meaning that any encoding errors show up there exactly as they will be written to file. Fixes #164
1 parent 19dc440 commit 6e8e0f7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Src/USaveInfoMgr.pas

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,18 @@ function TSaveInfoMgr.GenerateHTML(const AUseHiliting: Boolean;
231231
function TSaveInfoMgr.GenerateMarkdown: TEncodedData;
232232
var
233233
Doc: TMarkdownSnippetDoc;
234+
GeneratedData: TEncodedData;
234235
begin
235236
Assert(Supports(fView, ISnippetView),
236237
ClassName + '.GeneratePlainText: View is not a snippet view');
237238
Doc := TMarkdownSnippetDoc.Create(
238239
(fView as ISnippetView).Snippet.Kind <> skFreeform
239240
);
240241
try
241-
Result := Doc.Generate((fView as ISnippetView).Snippet);
242+
GeneratedData := Doc.Generate((fView as ISnippetView).Snippet);
243+
Result := TEncodedData.Create(
244+
GeneratedData.ToString, fSaveDlg.SelectedEncoding
245+
);
242246
finally
243247
Doc.Free;
244248
end;
@@ -264,13 +268,17 @@ function TSaveInfoMgr.GeneratePlainText: TEncodedData;
264268
var
265269
Doc: TTextSnippetDoc; // object that generates RTF document
266270
HiliteAttrs: IHiliteAttrs; // syntax highlighter formatting attributes
271+
GeneratedData: TEncodedData;
267272
begin
268273
Assert(Supports(fView, ISnippetView),
269274
ClassName + '.GeneratePlainText: View is not a snippet view');
270275
HiliteAttrs := THiliteAttrsFactory.CreateNulAttrs;
271276
Doc := TTextSnippetDoc.Create;
272277
try
273-
Result := Doc.Generate((fView as ISnippetView).Snippet);
278+
GeneratedData := Doc.Generate((fView as ISnippetView).Snippet);
279+
Result := TEncodedData.Create(
280+
GeneratedData.ToString, fSaveDlg.SelectedEncoding
281+
);
274282
finally
275283
Doc.Free;
276284
end;

0 commit comments

Comments
 (0)