Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit 07905fa

Browse files
committed
allow for clearing the selection of code when swapping tabs or loading a new pattern
1 parent ce82bad commit 07905fa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

public/styleguide/js/code-viewer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ var codeViewer = {
140140
*/
141141
swapCode: function(type) {
142142

143+
codeViewer.clearSelection();
143144
var fill = "";
144145
var className = (type == "c") ? "css" : "markup";
145146
$("#sg-code-fill").removeClass().addClass("language-"+className);
@@ -170,6 +171,19 @@ var codeViewer = {
170171
}
171172
},
172173

174+
/**
175+
* clear any selection of code when swapping tabs or opening a new pattern
176+
*/
177+
clearSelection: function() {
178+
if (codeViewer.codeActive) {
179+
if (window.getSelection().empty) {
180+
window.getSelection().empty();
181+
} else if (window.getSelection().removeAllRanges) {
182+
window.getSelection().removeAllRanges();
183+
}
184+
}
185+
},
186+
173187
/**
174188
* slides the panel
175189
*/
@@ -241,6 +255,9 @@ var codeViewer = {
241255
*/
242256
updateCode: function(lineage,lineageR,patternPartial,cssEnabled) {
243257

258+
// clear any selections that might have been made
259+
codeViewer.clearSelection();
260+
244261
// draw lineage
245262
if (lineage.length !== 0) {
246263
var lineageList = "";

0 commit comments

Comments
 (0)