Github user jmuehlner commented on a diff in the pull request:

    
https://github.com/apache/incubator-guacamole-client/pull/24#discussion_r68862714
  
    --- Diff: 
guacamole/src/main/webapp/app/clipboard/directives/guacClipboard.js ---
    @@ -0,0 +1,312 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +
    +/**
    + * A directive which exposes the current clipboard contents, if possible,
    + * allowing the user to edit those contents. If the current clipboard 
contents
    + * cannot be directly accessed, the user can at least directly copy/paste 
data
    + * within the field provided by this directive. The contents of this 
clipboard
    + * directive, whether retrieved from the local or manipulated manually by 
the
    + * user, are exposed via the "data" attribute. In addition to updating the
    + * "data" attribute, changes to clipboard data will be broadcast on the 
scope
    + * via "guacClipboard" events.
    + */
    +angular.module('clipboard').directive('guacClipboard', ['$injector',
    +    function guacClipboard($injector) {
    +
    +    // Required types
    +    var ClipboardData = $injector.get('ClipboardData');
    +
    +    /**
    +     * Configuration object for the guacClipboard directive.
    +     *
    +     * @type Object.<String, Object>
    +     */
    +    var config = {
    +        restrict    : 'E',
    +        replace     : true,
    +        templateUrl : 'app/clipboard/templates/guacClipboard.html'
    +    };
    +
    +    // Scope properties exposed by the guacClipboard directive
    +    config.scope = {
    +
    +        /**
    +         * The data to display within the field provided by this 
directive. If
    +         * the local clipboard can be accessed by JavaScript, this will be 
set
    +         * automatically as the local clipboard changes. Failing that, this
    +         * will be set when the user manually modifies the contents of the
    +         * field. Changes to this value will be rendered within the field 
and,
    +         * if possible, will be pushed to the local clipboard.
    +         *
    +         * @type ClipboardData
    +         */
    +        data : '='
    +
    +    };
    +
    +    // guacClipboard directive controller
    +    config.controller = ['$scope', '$injector', '$element',
    +            function guacClipboardController($scope, $injector, $element) {
    +
    +        // Required services
    +        var $rootScope       = $injector.get('$rootScope');
    +        var $window          = $injector.get('$window');
    +        var clipboardService = $injector.get('clipboardService');
    +
    +        /**
    +         * Reference to the window.document object.
    +         *
    +         * @private
    +         * @type HTMLDocument
    +         */
    +        var document = $window.document;
    +
    +        /**
    +         * Map of all currently pressed keys by keysym. If a particular 
key is
    +         * currently pressed, the value stored under that key's keysym 
within
    +         * this map will be true. All keys not currently pressed will not 
have entries
    +         * within this map.
    +         *
    +         * @type Object.<Number, Boolean>
    +         */
    +        var keysCurrentlyPressed = {};
    +
    +        /**
    +         * Map of all currently pressed keys (by keysym) to the clipboard
    +         * contents received while those keys were pressed. All keys not
    +         * currently pressed will not have entries within this map.
    +         *
    +         * @type Object.<Number, Blob>
    +         */
    +        var clipboardDataFromKey = {};
    +
    +        /**
    +         * The FileReader to use to read File or Blob data received from 
the
    +         * clipboard.
    +         *
    +         * @type FileReader
    +         */
    +        var reader = new FileReader();
    +
    +        /**
    +         * The content-editable DOM element which will contain the 
clipboard
    +         * contents within the user interface provided by this directive.
    +         *
    +         * @type Element
    +         */
    +        var element = $element[0];
    +
    +        // Intercept paste events, handling image data specifically
    +        element.addEventListener('paste', function dataPasted(e) {
    +
    +            // Always clear the current clipboard contents upon paste
    +            element.innerHTML = '';
    +
    +            // If we can't read the clipboard contents at all, abort
    +            var clipboardData = e.clipboardData;
    --- End diff --
    
    If there's a way to decide whether it's an image before clearing the text, 
I think that would be good to do. It's unexpected and undesirable in my opinion 
for all the text currently in the clipboard to disappear without warning if you 
paste more text. I think it will make people unhappy.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to