Skip to content

Commit e3ea9c8

Browse files
github-actions[bot]KB Bot
and
KB Bot
authored
Added new kb article editor-single-spaces-track-changes (#629)
Co-authored-by: KB Bot <[email protected]>
1 parent 2643c75 commit e3ea9c8

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Handling Single Spaces with Track Changes in RadEditor
3+
description: Learn how to ensure single spaces are visible when using track changes and switching between HTML and Edit views in RadEditor.
4+
type: how-to
5+
page_title: How to Make Single Spaces Visible with Track Changes in RadEditor
6+
slug: editor-single-spaces-track-changes
7+
tags: radeditor, asp.net ajax, track changes, html view, edit view, content filter
8+
res_type: kb
9+
ticketid: 1670384
10+
---
11+
12+
## Environment
13+
14+
| Product | Version |
15+
|---------------------------|----------|
16+
| RadEditor for ASP.NET AJAX| all|
17+
18+
## Description
19+
20+
When adding a single space in RadEditor with track changes enabled and then switching between HTML and Edit views, the space does not display. This issue occurs because the single space symbol is represented by the `&ZeroWidthSpace;` entity, which is not rendered by the browser in the Design mode of the editable iframe area. If two spaces are added, then it works as expected.
21+
22+
This KB article also answers the following questions:
23+
- How to ensure single spaces are visible with track changes in RadEditor?
24+
- How to display single spaces after switching views in RadEditor with track changes on?
25+
- How to implement a custom content filter in RadEditor for handling space visibility?
26+
27+
## Solution
28+
29+
To make single spaces visible when using track changes in RadEditor, implement a custom content filter that replaces the `&ZeroWidthSpace;` entity with a space. Use the following steps and code snippet to achieve this:
30+
31+
1. Add a RadEditor to your page and enable Track Changes.
32+
2. Implement the `ZeroWidthSpaceFilter` class in JavaScript to handle the replacement.
33+
3. Register the custom filter using the `OnClientLoad` event of RadEditor.
34+
35+
The following example demonstrates how to set up RadEditor and the custom content filter:
36+
37+
```html
38+
<telerik:RadEditor RenderMode="Lightweight" ID="theEditor" EnableTrackChanges="true" runat="server" OnClientLoad="OnClientLoad" ToolsFile="ToolsFile.xml">
39+
<TrackChangesSettings Author="RadEditorUser" CanAcceptTrackChanges="true" UserCssId="reU0"></TrackChangesSettings>
40+
<Content>
41+
<!-- Your content here -->
42+
</Content>
43+
</telerik:RadEditor>
44+
<script type="text/javascript">
45+
function OnClientLoad(editor, args) {
46+
editor.get_filtersManager().add(new ZeroWidthSpaceFilter());
47+
}
48+
49+
ZeroWidthSpaceFilter = function () {
50+
ZeroWidthSpaceFilter.initializeBase(this);
51+
this.set_isDom(false);
52+
this.set_enabled(true);
53+
this.set_name("Zero-Width Space Filter");
54+
this.set_description("Replaces &ZeroWidthSpace; and similar representations with &nbsp;");
55+
}
56+
57+
ZeroWidthSpaceFilter.prototype = {
58+
getHtmlContent: function (content) {
59+
// Do nothing for HTML content.
60+
return content;
61+
},
62+
63+
getDesignContent: function (content) {
64+
// Replace `&ZeroWidthSpace;` with a space.
65+
return content.replace(/&nbsp;/gi, ' '); // Replace named entity.
66+
}
67+
}
68+
69+
// Register the filter.
70+
ZeroWidthSpaceFilter.registerClass('ZeroWidthSpaceFilter', Telerik.Web.UI.Editor.Filter);
71+
</script>
72+
```
73+
74+
This approach ensures that single spaces added in RadEditor with track changes enabled are visible after switching between HTML view and Edit view.
75+
76+
## See Also
77+
78+
- [Implementing a Custom Filter](https://www.telerik.com/products/aspnet-ajax/documentation/controls/editor/managing-content/content-filters#implementing-a-custom-filter)
79+
- [RadEditor Overview](https://docs.telerik.com/aspnet-ajax/controls/editor/overview)

0 commit comments

Comments
 (0)