clear url hash when selection is cleared
This commit is contained in:
@@ -64,6 +64,7 @@ export default function EditorControls({
|
|||||||
setLanguage('plain');
|
setLanguage('plain');
|
||||||
history.replace({
|
history.replace({
|
||||||
pathname: '/',
|
pathname: '/',
|
||||||
|
hash: '',
|
||||||
});
|
});
|
||||||
document.title = 'paste';
|
document.title = 'paste';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState, useEffect, useRef } from 'react';
|
import { useState, useEffect, useRef } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import ReactEditor from 'react-simple-code-editor';
|
import ReactEditor from 'react-simple-code-editor';
|
||||||
|
import history from 'history/browser';
|
||||||
import EditorPrismStyle from './EditorPrismStyle';
|
import EditorPrismStyle from './EditorPrismStyle';
|
||||||
import { getHighlighter } from '../util/highlighting';
|
import { getHighlighter } from '../util/highlighting';
|
||||||
|
|
||||||
@@ -123,15 +124,19 @@ function useSelectedLine() {
|
|||||||
|
|
||||||
// update window hash when a new line is highlighted
|
// update window hash when a new line is highlighted
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let hash = '';
|
||||||
|
|
||||||
if (selected[0] !== -1) {
|
if (selected[0] !== -1) {
|
||||||
if (selected[1] !== -1) {
|
if (selected[1] !== -1) {
|
||||||
const start = Math.min(...selected);
|
const start = Math.min(...selected);
|
||||||
const end = Math.max(...selected);
|
const end = Math.max(...selected);
|
||||||
window.location.hash = `#L${start}-${end}`;
|
hash = `#L${start}-${end}`;
|
||||||
} else {
|
} else {
|
||||||
window.location.hash = `#L${selected[0]}`;
|
hash = `#L${selected[0]}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
history.replace({ hash });
|
||||||
}, [selected]);
|
}, [selected]);
|
||||||
|
|
||||||
// toggle the highlighting for a given line
|
// toggle the highlighting for a given line
|
||||||
|
|||||||
Reference in New Issue
Block a user