import { LineHandle } from './codemirror/lib/codemirror' ; import { LogEntryType } from '@/scripts/renderer/InspectorLogEntry' ; import { ShaderView } from './ShaderView' ; import store from '@/store' ; export default class ShaderLogMarker { private lineNumber : number ; private lineHandle : LineHandle ; private shader : ShaderView ; private type : LogEntryType ; constructor ( shader , lineNumber , descriptions , type ) { this . shader = shader ; this . lineNumber = lineNumber ; this . type = type ; const marker = this . createElement ( descriptions , type ) ; this . lineHandle = this . shader . doc . setGutterMarker ( lineNumber , 'CodeMirror-markers' , marker ) ; this . shader . doc . addLineClass ( lineNumber , 'wrap' , 'CodeMirror-markedline-' + type ) ; this . shader . doc . addLineClass ( lineNumber , 'gutter' , 'CodeMirror-markedline-gutter-' + type ) ; this . lineHandle . on ( 'change' , this . removeFromLog ) ; } public clear ( ) { this . shader . doc . setGutterMarker ( this . lineHandle , 'CodeMirror-markers' , null ) ; this . shader . doc . removeLineClass ( this . lineHandle , 'wrap' , 'CodeMirror-markedline-' + this . type ) ; this . shader . doc . removeLineClass ( this . lineHandle , 'gutter' , 'CodeMirror-markedline-gutter-' + this . type ) ; this . lineHandle . off ( 'change' , this . removeFromLog ) ; } private removeFromLog = ( ) => { const shader = this . shader . type ; const line = this . lineNumber ; store . commit ( 'CLEAR_LOG_LINE' , { shader , line } ) ; this . lineHandle . off ( 'change' , this . removeFromLog ) ; } ; private createElement ( descriptions , type ) { const marker = document . createElement ( 'div' ) ; marker . className = 'CodeMirror-marker-' + type ; const markerInfo = document . createElement ( 'div' ) ; markerInfo . className = 'CodeMirror-marker-info' ; marker . appendChild ( markerInfo ) ; const fragment = document . createDocumentFragment ( ) ; for ( let description of descriptions ) { let markerInfoItem = document . createElement ( 'span' ) ; markerInfoItem . innerText = description ; fragment . appendChild ( markerInfoItem ) ; } markerInfo . appendChild ( fragment ) ; marker . addEventListener ( 'mouseenter' , ( ) => { markerInfo . classList . add ( 'visible' ) ; } ) ; marker . addEventListener ( 'mouseout' , ( ) => { markerInfo . classList . remove ( 'visible' ) ; } ) ; return marker ; } }