Adjust editor config (#976)

* Adjust editor config

Signed-off-by: Tilman Vatteroth <tilman.vatteroth@tu-dortmund.de>
Co-authored-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Tilman Vatteroth 2021-02-03 22:13:04 +01:00 committed by GitHub
parent 0180c75e55
commit e12dc523f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
301 changed files with 4393 additions and 3741 deletions

View file

@ -1,8 +1,8 @@
/*
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
SPDX-License-Identifier: AGPL-3.0-only
*/
SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { RefObject, useCallback, useEffect, useState } from 'react'
import { Overlay, Tooltip } from 'react-bootstrap'
@ -22,15 +22,20 @@ export const CopyOverlay: React.FC<CopyOverlayProps> = ({ content, clickComponen
const [tooltipId] = useState<string>(() => uuid())
const copyToClipboard = useCallback((content: string) => {
navigator.clipboard.writeText(content).then(() => {
setError(false)
}).catch(() => {
setError(true)
console.error("couldn't copy")
}).finally(() => {
setShowCopiedTooltip(true)
setTimeout(() => { setShowCopiedTooltip(false) }, 2000)
})
navigator.clipboard.writeText(content)
.then(() => {
setError(false)
})
.catch(() => {
setError(true)
console.error('couldn\'t copy')
})
.finally(() => {
setShowCopiedTooltip(true)
setTimeout(() => {
setShowCopiedTooltip(false)
}, 2000)
})
}, [])
useEffect(() => {
@ -46,17 +51,17 @@ export const CopyOverlay: React.FC<CopyOverlayProps> = ({ content, clickComponen
}, [clickComponent, copyToClipboard, content])
return (
<Overlay target={clickComponent} show={showCopiedTooltip} placement="top">
{(props) => (
<Tooltip id={`copied_${tooltipId}`} {...props}>
<ShowIf condition={error}>
<Trans i18nKey={'common.copyError'}/>
<Overlay target={ clickComponent } show={ showCopiedTooltip } placement="top">
{ (props) => (
<Tooltip id={ `copied_${ tooltipId }` } { ...props }>
<ShowIf condition={ error }>
<Trans i18nKey={ 'common.copyError' }/>
</ShowIf>
<ShowIf condition={!error}>
<Trans i18nKey={'common.successfullyCopied'}/>
<ShowIf condition={ !error }>
<Trans i18nKey={ 'common.successfullyCopied' }/>
</ShowIf>
</Tooltip>
)}
) }
</Overlay>
)
}

View file

@ -15,25 +15,25 @@ export interface CopyToClipboardButtonProps {
content: string
size?: 'sm' | 'lg'
variant?: Variant
"data-cy"?: string
'data-cy'?: string
}
export const CopyToClipboardButton: React.FC<CopyToClipboardButtonProps> = ({
content,
size = 'sm',
variant = 'dark',
...props
}) => {
content,
size = 'sm',
variant = 'dark',
...props
}) => {
const { t } = useTranslation()
const button = useRef<HTMLButtonElement>(null)
return (
<Fragment>
<Button ref={button} size={size} variant={variant} title={t('renderer.highlightCode.copyCode')}
data-cy={props["data-cy"]}>
<Button ref={ button } size={ size } variant={ variant } title={ t('renderer.highlightCode.copyCode') }
data-cy={ props['data-cy'] }>
<ForkAwesomeIcon icon='files-o'/>
</Button>
<CopyOverlay content={content} clickComponent={button}/>
<CopyOverlay content={ content } clickComponent={ button }/>
</Fragment>
)
}

View file

@ -1,8 +1,8 @@
/*
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
SPDX-License-Identifier: AGPL-3.0-only
*/
SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { Fragment, useCallback, useRef } from 'react'
import { Button, FormControl, InputGroup } from 'react-bootstrap'
@ -25,9 +25,10 @@ export const CopyableField: React.FC<CopyableFieldProps> = ({ content, nativeSha
navigator.share({
text: content,
url: url
}).catch(err => {
console.error('Native sharing failed: ', err)
})
.catch(err => {
console.error('Native sharing failed: ', err)
})
}, [content, url])
const sharingSupported = typeof navigator.share === 'function'
@ -35,21 +36,21 @@ export const CopyableField: React.FC<CopyableFieldProps> = ({ content, nativeSha
return (
<Fragment>
<InputGroup className="my-3">
<FormControl readOnly={true} className={'text-center'} value={content} />
<FormControl readOnly={ true } className={ 'text-center' } value={ content }/>
<InputGroup.Append>
<Button variant="outline-secondary" ref={copyButton} title={'Copy'}>
<Button variant="outline-secondary" ref={ copyButton } title={ 'Copy' }>
<ForkAwesomeIcon icon='files-o'/>
</Button>
</InputGroup.Append>
<ShowIf condition={!!nativeShareButton && sharingSupported}>
<ShowIf condition={ !!nativeShareButton && sharingSupported }>
<InputGroup.Append>
<Button variant="outline-secondary" title={'Share'} onClick={doShareAction}>
<Button variant="outline-secondary" title={ 'Share' } onClick={ doShareAction }>
<ForkAwesomeIcon icon='share-alt'/>
</Button>
</InputGroup.Append>
</ShowIf>
</InputGroup>
<CopyOverlay content={content} clickComponent={copyButton}/>
<CopyOverlay content={ content } clickComponent={ copyButton }/>
</Fragment>
)
}