⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 range.py

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 PY
📖 第 1 页 / 共 3 页
字号:
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                self.startContainer.deleteData(self.startOffset,1+self.endOffset-self.startOffset)

            else:
                #Delete a set number of children
                numDel = self.endOffset - self.startOffset+1
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    ReleaseNode(c)

            self.__dict__['endContainer'] = self.startContainer
            self.__dict__['endOffset'] = self.endContainer
            self.__dict__['commonAncestorContainer'] = self.endContainer
            self.__dict__['collapsed'] = 1

        elif self.startContainer == self.commonAncestorContainer:
            #Delete up the endContainer
            #From the start to the end
            if self.endContainer.nodeType in [Node.TEXT_NODE,
                                              Node.COMMENT_NODE,
                                              Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                self.endContainer.deleteData(0,self.endOffset)
            else:
                numDel = self.endOffset
                for ctr in range(numDel):
                    c = self.endContainer.removeChild(self.endContainer.childNodes[0])
                    ReleaseNode(c)

            cur = self.endContainer
            while cur.parentNode != self.commonAncestorContainer:
                while cur.previousSibling:
                    c = cur.parentNode.removeChild(cur.previousSibling)
                    ReleaseNode(c)
                cur = cur.parentNode

            #Delete up to the ancestor of end
            endAncestorChild = cur
            while self.startContainer.firstChild != endAncestorChild:
                c = self.startContainer.removeChild(self.startContainer.firstChild)
                ReleaseNode(c)
        elif self.endContainer == self.commonAncestorContainer:
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                self.startContainer.deleteData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
            else:
                numDel = len(self.startContainer.childNodes) - self.startOffset
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    ReleaseNode(c)

            cur = self.startContainer
            while cur.parentNode != self.commonAncestorContainer:
                while cur.nextSibling:
                    c = cur.parentNode.removeChild(cur.nextSibling)
                    ReleaseNode(c)
                cur = cur.parentNode

            startAncestorChild = cur

            #Delete up to the ancestor of start
            startAncestorChild = cur
            startIndex = self.endContainer.childNodes.index(cur)
            numDel = self.endOffset - startIndex
            for ctr in range(numDel):
                c = self.endContainer.removeChild(startAncestorChild.nextSibling)
                ReleaseNode(c)

        else:
            #From the start to the end
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                self.startContainer.deleteData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
            else:
                numDel = len(self.startContainer.childNodes) - self.startOffset
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    ReleaseNode(c)

            cur = self.startContainer
            while cur.parentNode != self.commonAncestorContainer:
                while cur.nextSibling:
                    c = cur.parentNode.removeChild(cur.nextSibling)
                    ReleaseNode(c)
                cur = cur.parentNode

            startAncestorChild = cur
            #Delete up the endContainer
            #From the start to the end
            if self.endContainer.nodeType in [Node.TEXT_NODE,
                                              Node.COMMENT_NODE,
                                              Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                self.endContainer.deleteData(0,self.endOffset)
            else:
                numDel = self.endOffset
                for ctr in range(numDel):
                    c = self.endContainer.removeChild(self.endContainer.childNodes[0])
                    ReleaseNode(c)

            cur = self.endContainer
            while cur.parentNode != self.commonAncestorContainer:
                while cur.previousSibling:
                    c = cur.parentNode.removeChild(cur.previousSibling)
                    ReleaseNode(c)
                cur = cur.parentNode

            endAncestorChild = cur

            cur = startAncestorChild
            #Delete everything between us
            while cur.nextSibling != endAncestorChild:
                c = cur.parentNode.removeChild(cur.nextSibling)
                ReleaseNode(c)

        #Adjust the containers
        #FIXME What the heck is the spec talking about??
        self.__dict__['endContainer'] = self.startContainer
        self.__dict__['endOffset'] = self.startContainer
        self.__dict__['commonAncestorContainer'] = self.startContainer
        self.__dict__['collapsed'] = 1

        return None

    def detach(self):
        self.detached = 1
        del self.startContainer
        del self.endContainer
        del self.startOffset
        del self.endOffset
        del self.collapsed
        del self.commonAncestorContainer

    def extractContents(self):
        """Extract the contents defined by this range"""


        if self.detached:
            raise InvalidStateErr()

        df = self._ownerDocument.createDocumentFragment()

        if self.startContainer == self.endContainer:
            if self.startOffset == self.endOffset:
                return df
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                data = self.startContainer.substringData(self.startOffset,1+self.endOffset-self.startOffset)
                self.startContainer.deleteData(self.startOffset,1+self.endOffset-self.startOffset)

                tx = self._ownerDocument.createTextNode(data)
                df.appendChild(tx)

            else:
                #Extrace a set number of children

                numDel = self.endOffset - self.startOffset+1
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    df.appendChild(c)

        elif self.startContainer == self.commonAncestorContainer:
            #Delete up the endContainer
            #From the start to the end
            lastKids = []
            copyData = None
            #Delete up the endContainer
            #From the start to the end
            if self.endContainer.nodeType in [Node.TEXT_NODE,
                                              Node.COMMENT_NODE,
                                              Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                copyData = self.endContainer.substringData(0,self.endOffset)
                self.endContainer.deleteData(0,self.endOffset)
            else:
                numDel = self.endOffset
                for ctr in range(numDel):
                    c = self.endContainer.removeChild(self.endContainer.childNodes[0])
                    lastKids.append(c)

            cur = self.endContainer
            while cur.parentNode != self.commonAncestorContainer:

                #Clone all of the way up
                newCur = cur.cloneNode(0)
                if copyData:
                    newCur.data = copyData
                    copyData = None
                for k in lastKids:
                    newCur.appendChild(k)
                lastKids = [newCur]

                while cur.previousSibling:
                    c = cur.parentNode.removeChild(cur.previousSibling)
                    lastKids = [c] + lastKids
                cur = cur.parentNode

            newEnd = cur.cloneNode(0)
            for k in lastKids:
                newEnd.appendChild(k)

            endAncestorChild = cur

            #Extract up to the ancestor of end
            while self.startContainer.firstChild != endAncestorChild:
                c = self.startContainer.removeChild(self.startContainer.firstChild)
                df.appendChild(c)
            df.appendChild(newEnd)

        elif self.endContainer == self.commonAncestorContainer:
            lastKids = []
            copyData = None
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data

                copyData = self.startContainer.substringData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
                self.startContainer.deleteData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
            else:
                numDel = len(self.startContainer.childNodes) - self.startOffset
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    lastKids.append(c)

            cur = self.startContainer
            while cur.parentNode != self.commonAncestorContainer:
                #Clone all of the way up
                newCur = cur.cloneNode(0)
                if copyData:
                    newCur.data = copyData
                    copyData = None
                for k in lastKids:
                    newCur.appendChild(k)
                lastKids = [newCur]

                while cur.nextSibling:
                    c = cur.parentNode.removeChild(cur.nextSibling)
                    lastKids.append(c)
                cur = cur.parentNode

            startAncestorChild = cur
            newStart = cur.cloneNode(0)
            for k in lastKids:
                newStart.appendChild(k)

            df.appendChild(newStart)


            #Extract up to the ancestor of start
            startAncestorChild = cur
            startIndex = self.endContainer.childNodes.index(cur)
            lastAdded = None
            numDel = self.endOffset - startIndex
            for ctr in range(numDel):
                c = self.endContainer.removeChild(startAncestorChild.nextSibling)
                df.insertBefore(c,lastAdded)
                lastAdded = c

        else:
            #From the start to the end
            lastStartKids = []
            startCopyData = None
            if self.startContainer.nodeType in [Node.TEXT_NODE,
                                                Node.COMMENT_NODE,
                                                Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data

                startCopyData = self.startContainer.substringData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
                self.startContainer.deleteData(self.startOffset,1+len(self.startContainer.data)-self.startOffset)
            else:
                numDel = len(self.startContainer.childNodes) - self.startOffset
                for ctr in range(numDel):
                    c = self.startContainer.removeChild(self.startContainer.childNodes[self.startOffset])
                    lastStartKids.append(c)

            cur = self.startContainer
            while cur.parentNode != self.commonAncestorContainer:
                #Clone all of the way up
                newCur = cur.cloneNode(0)
                if startCopyData:
                    newCur.data = startCopyData
                    startCopyData = None
                for k in lastStartKids:
                    newCur.appendChild(k)
                lastStartKids = [newCur]

                while cur.nextSibling:
                    c = cur.parentNode.removeChild(cur.nextSibling)
                    lastStartKids.append(c)
                cur = cur.parentNode

            startAncestorChild = cur

            newStart = cur.cloneNode(0)
            for k in lastStartKids:
                newStart.appendChild(k)

            df.appendChild(newStart)


            lastEndKids = []
            endCopyData = None
            #Delete up the endContainer
            #From the start to the end
            if self.endContainer.nodeType in [Node.TEXT_NODE,
                                              Node.COMMENT_NODE,
                                              Node.PROCESSING_INSTRUCTION_NODE]:
                #Adjust the character data
                endCopyData = self.endContainer.substringData(0,self.endOffset)
                self.endContainer.deleteData(0,self.endOffset)
            else:
                numDel = self.endOffset
                for ctr in range(numDel):
                    c = self.endContainer.removeChild(self.endContainer.childNodes[0])
                    lastEndKids.append(c)

            cur = self.endContainer
            while cur.parentNode != self.commonAncestorContainer:
                newCur = cur.cloneNode(0)
                if endCopyData:
                    newCur.data = endCopyData
                    endCopyData = None
                for k in lastEndKids:
                    newCur.appendChild(k)
                lastEndKids = [newCur]
                while cur.previousSibling:
                    c = cur.parentNode.removeChild(cur.previousSibling)
                    lastEndKids = [c] + lastEndKids
                cur = cur.parentNode

            endAncestorChild = cur

            newEnd = cur.cloneNode(0)
            for k in lastEndKids:
                newEnd.appendChild(k)


            cur = startAncestorChild
            #Extract everything between us
            while cur.nextSibling != endAncestorChild:
                c = cur.parentNode.removeChild(cur.nextSibling)
                df.appendChild(c)
            df.appendChild(newEnd)


        #Adjust the containers
        #FIXME What the heck is the spec talking about??
        self.__dict__['endContainer'] = self.startContainer
        self.__dict__['endOffset'] = self.startContainer
        self.__dict__['commonAncestorContainer'] = self.startContainer
        self.__dict__['collapsed'] = 1



        return df


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -